diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2019-03-20 21:34:30 +0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2019-03-20 22:51:46 +0300 |
commit | 3fd8e612719dbeb9d4790aef6875b005d9dd6aff (patch) | |
tree | d577bc2b71ad6277cfeca71badba9c7baa72c43d /app/models/concerns/cache_markdown_field.rb | |
parent | cc5095edfce2b4d4083a4fb1cdc7c0a1898b9921 (diff) |
Add option to not exclude _html fields from attributes
Diffstat (limited to 'app/models/concerns/cache_markdown_field.rb')
-rw-r--r-- | app/models/concerns/cache_markdown_field.rb | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/app/models/concerns/cache_markdown_field.rb b/app/models/concerns/cache_markdown_field.rb index 1a8570b80c3..4212224b66a 100644 --- a/app/models/concerns/cache_markdown_field.rb +++ b/app/models/concerns/cache_markdown_field.rb @@ -7,6 +7,7 @@ # cache_markdown_field :foo # cache_markdown_field :bar # cache_markdown_field :baz, pipeline: :single_line +# cache_markdown_field :baz, hidden: false # # Corresponding foo_html, bar_html and baz_html fields should exist. module CacheMarkdownField @@ -37,7 +38,15 @@ module CacheMarkdownField end def html_fields - markdown_fields.map {|field| html_field(field) } + markdown_fields.map { |field| html_field(field) } + end + + def hidden_html_fields + markdown_fields.each_with_object([]) do |field, fields| + if @data[field].fetch(:hidden, true) + fields << html_field(field) + end + end end end @@ -149,13 +158,17 @@ module CacheMarkdownField alias_method :attributes_before_markdown_cache, :attributes def attributes attrs = attributes_before_markdown_cache + html_fields = cached_markdown_fields.html_fields + hidden_html_fields = cached_markdown_fields.hidden_html_fields - attrs.delete('cached_markdown_version') - - cached_markdown_fields.html_fields.each do |field| + hidden_html_fields.each do |field| attrs.delete(field) end + if (html_fields - hidden_html_fields).empty? + attrs.delete('cached_markdown_version') + end + attrs end |