Module: Curlybars
- Defined in:
- lib/curlybars.rb,
lib/curlybars/lexer.rb,
lib/curlybars/parser.rb,
lib/curlybars/generic.rb,
lib/curlybars/railtie.rb,
lib/curlybars/version.rb,
lib/curlybars/visitor.rb,
lib/curlybars/position.rb,
lib/curlybars/error/lex.rb,
lib/curlybars/node/item.rb,
lib/curlybars/node/path.rb,
lib/curlybars/node/root.rb,
lib/curlybars/node/text.rb,
lib/curlybars/presenter.rb,
lib/curlybars/error/base.rb,
lib/curlybars/error/parse.rb,
lib/curlybars/node/option.rb,
lib/curlybars/node/output.rb,
lib/curlybars/node/string.rb,
lib/curlybars/safe_buffer.rb,
lib/curlybars/error/render.rb,
lib/curlybars/node/boolean.rb,
lib/curlybars/node/if_else.rb,
lib/curlybars/node/literal.rb,
lib/curlybars/node/partial.rb,
lib/curlybars/configuration.rb,
lib/curlybars/error/compile.rb,
lib/curlybars/node/template.rb,
lib/curlybars/node/variable.rb,
lib/curlybars/error/validate.rb,
lib/curlybars/node/each_else.rb,
lib/curlybars/node/with_else.rb,
lib/curlybars/processor/tilde.rb,
lib/curlybars/method_whitelist.rb,
lib/curlybars/node/unless_else.rb,
lib/curlybars/template_handler.rb,
lib/curlybars/rendering_support.rb,
lib/curlybars/dependency_tracker.rb,
lib/curlybars/node/sub_expression.rb,
lib/curlybars/node/block_helper_else.rb,
lib/curlybars/processor/token_factory.rb,
lib/curlybars/error/presenter/not_found.rb
Overview
rubocop:disable Style/RegexpLiteral, Style/Semicolon
Defined Under Namespace
Modules: Error, MethodWhitelist, Node, Processor Classes: Configuration, DependencyTracker, Generic, Lexer, Parser, Position, Presenter, Railtie, RenderingSupport, SafeBuffer, TemplateHandler, Visitor
Constant Summary collapse
- VERSION =
'1.12.0'
Class Attribute Summary collapse
Class Method Summary collapse
-
.compile(source, identifier = nil) ⇒ Object
Compiles a Curlybars template to Ruby code.
- .configure {|configuration| ... } ⇒ Object
- .global_helpers_dependency_tree ⇒ Object
- .reset ⇒ Object
-
.valid?(presenter_class, source, identifier = nil, **options) ⇒ Boolean
Check if the source is valid for a given presenter.
-
.validate(dependency_tree, source, identifier = nil, **options) ⇒ Object
Validates the source against a presenter.
-
.visit(visitor, source, identifier = nil) ⇒ Object
Visit nodes in the AST.
Class Attribute Details
.cache ⇒ Object
88 89 90 |
# File 'lib/curlybars.rb', line 88 def cache @cache ||= ActiveSupport::Cache::MemoryStore.new end |
.configuration ⇒ Object
6 7 8 |
# File 'lib/curlybars/configuration.rb', line 6 def self.configuration @configuration ||= Configuration.new end |
Class Method Details
.compile(source, identifier = nil) ⇒ Object
Compiles a Curlybars template to Ruby code.
source - The source HBS String that should be compiled. identifier - The the file name of the template being compiled (defaults to ‘nil`).
Returns a String containing the Ruby code.
28 29 30 31 32 33 34 |
# File 'lib/curlybars.rb', line 28 def compile(source, identifier = nil) cache_key = ["Curlybars.compile", identifier, Digest::SHA256.hexdigest(source)] cache.fetch(cache_key) do ast(transformed_source(source), identifier, run_processors: true).compile end end |
.configure {|configuration| ... } ⇒ Object
10 11 12 |
# File 'lib/curlybars/configuration.rb', line 10 def self.configure yield(configuration) end |
.global_helpers_dependency_tree ⇒ Object
81 82 83 84 85 86 |
# File 'lib/curlybars.rb', line 81 def global_helpers_dependency_tree @global_helpers_dependency_tree ||= begin classes = Curlybars.configuration.global_helpers_provider_classes classes.map(&:dependency_tree).inject({}, :merge) end end |
.reset ⇒ Object
14 15 16 |
# File 'lib/curlybars/configuration.rb', line 14 def self.reset @configuration = Configuration.new end |
.valid?(presenter_class, source, identifier = nil, **options) ⇒ Boolean
Check if the source is valid for a given presenter.
presenter_class - the presenter class, used to check if the source is valid. source - The source HBS String that should be check to be valid. identifier - The the file name of the template being checked (defaults to ‘nil`).
Returns true if the template is valid, false otherwise.
66 67 68 69 |
# File 'lib/curlybars.rb', line 66 def valid?(presenter_class, source, identifier = nil, **) errors = validate(presenter_class, source, identifier, **) errors.empty? end |
.validate(dependency_tree, source, identifier = nil, **options) ⇒ Object
Validates the source against a presenter.
dependency_tree - a presenter dependency tree as defined in Curlybars::MethodWhitelist source - The source HBS String that should be validated. identifier - The the file name of the template being validated (defaults to ‘nil`).
Returns an array of Curlybars::Error::Validation
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/curlybars.rb', line 43 def validate(dependency_tree, source, identifier = nil, **) .reverse_merge!( run_processors: true ) errors = begin branches = [dependency_tree] ast(source, identifier, run_processors: [:run_processors]).validate(branches) rescue Curlybars::Error::Base => ast_error [ast_error] end errors.flatten! errors.compact! errors end |
.visit(visitor, source, identifier = nil) ⇒ Object
Visit nodes in the AST.
visitor - An instance of a subclass of ‘Curlybars::Visitor`. source - The source HBS String used to generate an AST. identifier - The the file name of the template being checked (defaults to `nil`).
76 77 78 79 |
# File 'lib/curlybars.rb', line 76 def visit(visitor, source, identifier = nil) tree = ast(transformed_source(source), identifier, run_processors: true) visitor.accept(tree) end |