Class: Fierce::PartialFinder
- Inherits:
-
Object
- Object
- Fierce::PartialFinder
- Defined in:
- lib/fierce/partial_finder.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#custom_presenter ⇒ Object
readonly
Returns the value of attribute custom_presenter.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #dir(p) ⇒ Object
-
#initialize(name, path, custom_presenter, context) ⇒ PartialFinder
constructor
A new instance of PartialFinder.
- #local_path ⇒ Object
- #mustache_partial ⇒ Object
- #partial_path ⇒ Object
- #perform ⇒ Object
- #presenter_partials ⇒ Object
- #presenter_path ⇒ Object
Constructor Details
#initialize(name, path, custom_presenter, context) ⇒ PartialFinder
Returns a new instance of PartialFinder.
5 6 7 8 9 10 |
# File 'lib/fierce/partial_finder.rb', line 5 def initialize(name, path, custom_presenter, context) @name = name @path = path @custom_presenter = custom_presenter @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/fierce/partial_finder.rb', line 3 def context @context end |
#custom_presenter ⇒ Object (readonly)
Returns the value of attribute custom_presenter.
3 4 5 |
# File 'lib/fierce/partial_finder.rb', line 3 def custom_presenter @custom_presenter end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/fierce/partial_finder.rb', line 3 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/fierce/partial_finder.rb', line 3 def path @path end |
Instance Method Details
#dir(p) ⇒ Object
30 31 32 33 34 |
# File 'lib/fierce/partial_finder.rb', line 30 def dir(p) parts = p.split('/') dir = parts[0..parts.length-2] dir.join('/') end |
#local_path ⇒ Object
26 27 28 |
# File 'lib/fierce/partial_finder.rb', line 26 def local_path "#{dir(path)}/#{name}" end |
#mustache_partial ⇒ Object
36 37 38 39 40 |
# File 'lib/fierce/partial_finder.rb', line 36 def mustache_partial context.lookup_context.find_template(partial_path, [], true, [], { handlers: [:mustache] }) rescue false end |
#partial_path ⇒ Object
22 23 24 |
# File 'lib/fierce/partial_finder.rb', line 22 def partial_path @partial_path ||= presenter_path || local_path end |
#perform ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/fierce/partial_finder.rb', line 42 def perform if template = mustache_partial template.source else context.render partial: partial_path end end |
#presenter_partials ⇒ Object
12 13 14 15 |
# File 'lib/fierce/partial_finder.rb', line 12 def presenter_partials return unless custom_presenter && custom_presenter.respond_to?(:partials) custom_presenter.partials.symbolize_keys end |
#presenter_path ⇒ Object
17 18 19 20 |
# File 'lib/fierce/partial_finder.rb', line 17 def presenter_path return unless presenter_partials presenter_partials[name] end |