From 82bb004e82cb1074359085f78633fbf108575086 Mon Sep 17 00:00:00 2001 From: Sharon Rosner Date: Thu, 7 Mar 2024 20:04:05 +0100 Subject: [PATCH] Rename emit_props to emit_attributes --- lib/papercraft/html.rb | 18 +++++++++--------- lib/papercraft/tags.rb | 38 +++++++++++++++++++------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/papercraft/html.rb b/lib/papercraft/html.rb index abbcf5d..5e1702e 100644 --- a/lib/papercraft/html.rb +++ b/lib/papercraft/html.rb @@ -11,11 +11,11 @@ module HTML # Emits the p tag (overrides Object#p) # # @param text [String] text content of tag - # @param **props [Hash] tag attributes + # @param **attributes [Hash] tag attributes # @para block [Proc] nested HTML block # @return [void] - def p(text = nil, **props, &block) - method_missing(:p, text, **props, &block) + def p(text = nil, **attributes, &block) + method_missing(:p, text, **attributes, &block) end S_HTML5_DOCTYPE = '' @@ -48,11 +48,11 @@ def link_stylesheet(href, custom_attributes = nil) # Emits an inline CSS style element. # # @param css [String] CSS code - # @param **props [Hash] optional element attributes + # @param **attributes [Hash] optional element attributes # @return [void] - def style(css, **props, &block) + def style(css, **attributes, &block) @buffer << '' << css << '' end @@ -60,11 +60,11 @@ def style(css, **props, &block) # Emits an inline JS script element. # # @param js [String, nil] Javascript code - # @param **props [Hash] optional element attributes + # @param **attributes [Hash] optional element attributes # @return [void] - def script(js = nil, **props, &block) + def script(js = nil, **attributes, &block) @buffer << '' << js << '' diff --git a/lib/papercraft/tags.rb b/lib/papercraft/tags.rb index e6f7f23..0e3dbae 100644 --- a/lib/papercraft/tags.rb +++ b/lib/papercraft/tags.rb @@ -23,18 +23,18 @@ module Tags S_TAG_%s_PRE = %s S_TAG_%s_CLOSE = %s - def %s(text = nil, _for: nil, **props, &block) + def %s(text = nil, _for: nil, **attributes, &block) return if @render_fragment && @fragment != @render_fragment - return _for.each { |*a| %s(text, **props) { block.(*a)} } if _for + return _for.each { |*a| %s(text, **attributes) { block.(*a)} } if _for - if text.is_a?(Hash) && props.empty? - props = text + if text.is_a?(Hash) && attributes.empty? + attributes = text text = nil end @buffer << S_TAG_%s_PRE - emit_props(props) unless props.empty? + emit_attributes(attributes) unless attributes.empty? if block @buffer << S_GT @@ -57,18 +57,18 @@ def %s(text = nil, _for: nil, **props, &block) S_TAG_%s_PRE = %s S_TAG_%s_CLOSE = %s - def %s(text = nil, _for: nil, **props, &block) + def %s(text = nil, _for: nil, **attributes, &block) return if @render_fragment && @fragment != @render_fragment - return _for.each { |*a| %s(text, **props) { block.(*a)} } if _for + return _for.each { |*a| %s(text, **attributes) { block.(*a)} } if _for - if text.is_a?(Hash) && props.empty? - props = text + if text.is_a?(Hash) && attributes.empty? + attributes = text text = nil end @buffer << S_TAG_%s_PRE - emit_props(props) unless props.empty? + emit_attributes(attributes) unless attributes.empty? if block @buffer << S_GT @@ -164,22 +164,22 @@ def defer(&block) # # @param sym [Symbol, String] XML tag # @param text [String, nil] tag content - # @param **props [Hash] tag attributes + # @param **attributes [Hash] tag attributes # @return [void] - def tag(sym, text = nil, _for: nil, **props, &block) + def tag(sym, text = nil, _for: nil, **attributes, &block) return if @render_fragment && @fragment != @render_fragment - return _for.each { |*a| tag(sym, text, **props) { block.(*a)} } if _for + return _for.each { |*a| tag(sym, text, **attributes) { block.(*a)} } if _for - if text.is_a?(Hash) && props.empty? - props = text + if text.is_a?(Hash) && attributes.empty? + attributes = text text = nil end tag = tag_repr(sym) @buffer << S_LT << tag - emit_props(props) unless props.empty? + emit_attributes(attributes) unless attributes.empty? if block @buffer << S_GT @@ -386,10 +386,10 @@ def att_repr(att) # Emits tag attributes into the rendering buffer. # - # @param props [Hash] tag attributes + # @param attributes [Hash] tag attributes # @return [void] - def emit_props(props) - props.each { |k, v| + def emit_attributes(attributes) + attributes.each { |k, v| case v when true @buffer << S_SPACE << att_repr(k)