Module: Hyperspeed
- Defined in:
- lib/hyperspeed.rb,
lib/hyperspeed/version.rb
Overview
rubocop:disable Style/CommentedKeyword
Defined Under Namespace
Classes: DefinitionProxy, Error
Constant Summary collapse
- VERSION =
'0.2.0'
Class Method Summary collapse
- .define(&block) ⇒ Object
-
.render(ast = nil) ⇒ Object
rubocop:disable Metrics/AbcSize.
Class Method Details
.define(&block) ⇒ Object
9 10 11 12 |
# File 'lib/hyperspeed.rb', line 9 def self.define(&block) definition_proxy = DefinitionProxy.new definition_proxy.evaluate(&block) end |
.render(ast = nil) ⇒ Object
rubocop:disable Metrics/AbcSize
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hyperspeed.rb', line 15 def self.render(ast = nil) # &block ast ||= define(&Proc.new) if ast[:type] == :ELEMENT tag_name = ast[:tag].to_s.downcase # ensure the string we are reducing isn't frozen, so that we can modify it content = ast[:children]&.reduce(+'') { |memo, child| memo << render(child) } if ast[:properties] properties = dasherize_nested_hash_keys(ast[:properties]) .map { |k, v| %(#{k}="#{meld(v)}") } .join(' ') %(<#{tag_name} #{properties}>#{content}</#{tag_name}>) else %(<#{tag_name}>#{content}</#{tag_name}>) end elsif ast[:type] == :TEXT ast[:value].to_s else fail 'Root `type` must be either ELEMENT or TEXT!' end end |