Class: Curlybars::Node::Partial
- Inherits:
-
Struct
- Object
- Struct
- Curlybars::Node::Partial
- Defined in:
- lib/curlybars/node/partial.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
-
#position ⇒ Object
Returns the value of attribute position.
Instance Method Summary collapse
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options
3 4 5 |
# File 'lib/curlybars/node/partial.rb', line 3 def @options end |
#path ⇒ Object
Returns the value of attribute path
3 4 5 |
# File 'lib/curlybars/node/partial.rb', line 3 def path @path end |
#position ⇒ Object
Returns the value of attribute position
3 4 5 |
# File 'lib/curlybars/node/partial.rb', line 3 def position @position end |
Instance Method Details
#cache_key ⇒ Object
98 99 100 101 102 103 |
# File 'lib/curlybars/node/partial.rb', line 98 def cache_key [ path, ].flatten.map(&:cache_key).push(position&.file_name, self.class.name).join("/") end |
#compile ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/curlybars/node/partial.rb', line 4 def compile = .map do |option| "options.merge!(#{option.compile})" end.join("\n") # NOTE: the following is a heredoc string, representing the ruby code fragment # outputted by this node. <<-RUBY options = ::ActiveSupport::HashWithIndifferentAccess.new #{} partial_source = rendering.resolve_partial(#{path.path.inspect}) if partial_source buffer.concat(rendering.render_partial(partial_source, #{path.path.inspect}, options).to_s) else buffer.concat(rendering.cached_call(#{path.compile}).to_s) end RUBY end |
#validate(branches, context: nil) ⇒ Object
24 25 26 27 28 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/curlybars/node/partial.rb', line 24 def validate(branches, context: nil) # Validate option expressions in current scope errors = .flat_map { |option| option.expression.validate(branches) } return errors unless context&.partial_resolver partial_source = begin context.partial_resolver.call(path.path) rescue StandardError nil end if partial_source if position.file_name == :"partials/#{path.path}" errors << Curlybars::Error::Validate.new( 'self_referencing_partial', "'#{path.path}' cannot reference itself", position ) return errors end = .each_with_object({}) do |option, tree| expr = option.expression tree[option.key.to_sym] = if expr.respond_to?(:resolve) begin expr.resolve(branches) rescue Curlybars::Error::Validate nil end end end if context.valid? partial_errors = Curlybars.validate( , partial_source, :"partials/#{path.path}", validation_context: context.increment_depth, run_processors: false ) inclusion_chain_entry = Curlybars::Position.new( position.file_name, position.line_number, position.line_offset, position.length ) partial_errors.each do |e| e.[:inclusion_chain] = (e.[:inclusion_chain] || []).push(inclusion_chain_entry) end errors.concat(partial_errors) else errors << Curlybars::Error::Validate.new( 'partial_nesting_limit_reached', "'#{path.path}' exceeds the partial nesting limit of #{Curlybars.configuration.partial_nesting_limit}", position ) end else path_errors = Array(path.validate(branches, check_type: :partial)) if path_errors.any? && context&.partial_resolver errors << Curlybars::Error::Validate.new( 'partial_not_found', "'#{path.path}' partial could not be found", position ) else errors.concat(path_errors) end end errors end |