Class: Fragmentary::FragmentsHelper::CacheBuilder

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::CacheHelper, ActionView::Helpers::TextHelper
Defined in:
lib/fragmentary/fragments_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, fragment = nil) ⇒ CacheBuilder

Returns a new instance of CacheBuilder.



24
25
26
27
# File 'lib/fragmentary/fragments_helper.rb', line 24

def initialize(template, fragment = nil)
  @fragment = fragment
  @template = template
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (private)



60
61
62
# File 'lib/fragmentary/fragments_helper.rb', line 60

def method_missing(method, *args)
  @fragment.send(method, *args)
end

Instance Attribute Details

#fragmentObject (readonly)

Returns the value of attribute fragment.



22
23
24
# File 'lib/fragmentary/fragments_helper.rb', line 22

def fragment
  @fragment
end

Instance Method Details

#cache_fragment(options, &block) ⇒ Object Also known as: cache_child



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fragmentary/fragments_helper.rb', line 29

def cache_fragment(options, &block)
  no_cache = options.delete(:no_cache)
  insert_widgets = options.delete(:insert_widgets)
  options.reverse_merge!(:user => Template.new(@template).current_user)
  # If the CacheBuilder was instantiated with an existing fragment, next_fragment is its child;
  # otherwise it is the root fragment specified by the options provided.
  next_fragment = @fragment.try(:child, options) || Fragmentary::Fragment.base_class.root(options)
  builder = CacheBuilder.new(@template, next_fragment)
  unless no_cache
    @template.cache next_fragment, :skip_digest => true do
      if Fragmentary.config.insert_timestamps
        @template.safe_concat("<!-- #{next_fragment.type} #{next_fragment.id} cached by Fragmentary version #{VERSION} at #{Time.now.utc} -->")
        if deployed_at && release_name
          @template.safe_concat("<!-- Cached using application release #{release_name} deployed at #{deployed_at} -->")
        end
        yield(builder)
        @template.safe_concat("<!-- #{next_fragment.type} #{next_fragment.id} ends -->")
      else
        yield(builder)
      end
    end
  else
    yield(builder)
  end
  @template.output_buffer = WidgetParser.new(@template).parse_buffer if (!@fragment || insert_widgets)
end