Skip to content

Commit

Permalink
Rename emit_props to emit_attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
noteflakes committed Mar 7, 2024
1 parent d8ac7df commit 82bb004
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
18 changes: 9 additions & 9 deletions lib/papercraft/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<!DOCTYPE html>'
Expand Down Expand Up @@ -48,23 +48,23 @@ 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 << '<style'
emit_props(props) unless props.empty?
emit_attributes(attributes) unless attributes.empty?

@buffer << '>' << css << '</style>'
end

# 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 << '<script'
emit_props(props) unless props.empty?
emit_attributes(attributes) unless attributes.empty?

if js
@buffer << '>' << js << '</script>'
Expand Down
38 changes: 19 additions & 19 deletions lib/papercraft/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ module Tags
S_TAG_%<TAG>s_PRE = %<tag_pre>s
S_TAG_%<TAG>s_CLOSE = %<tag_close>s
def %<tag>s(text = nil, _for: nil, **props, &block)
def %<tag>s(text = nil, _for: nil, **attributes, &block)
return if @render_fragment && @fragment != @render_fragment
return _for.each { |*a| %<tag>s(text, **props) { block.(*a)} } if _for
return _for.each { |*a| %<tag>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_%<TAG>s_PRE
emit_props(props) unless props.empty?
emit_attributes(attributes) unless attributes.empty?
if block
@buffer << S_GT
Expand All @@ -57,18 +57,18 @@ def %<tag>s(text = nil, _for: nil, **props, &block)
S_TAG_%<TAG>s_PRE = %<tag_pre>s
S_TAG_%<TAG>s_CLOSE = %<tag_close>s
def %<tag>s(text = nil, _for: nil, **props, &block)
def %<tag>s(text = nil, _for: nil, **attributes, &block)
return if @render_fragment && @fragment != @render_fragment
return _for.each { |*a| %<tag>s(text, **props) { block.(*a)} } if _for
return _for.each { |*a| %<tag>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_%<TAG>s_PRE
emit_props(props) unless props.empty?
emit_attributes(attributes) unless attributes.empty?
if block
@buffer << S_GT
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 82bb004

Please sign in to comment.