class Navigator::Tag
Renders a HTML tag.
Attributes
Public Class Methods
Source
# File lib/navigator/tag.rb, line 8 def self.names_without_suffix = %w[img input] # rubocop:disable Metrics/ParameterLists def initialize name, content = nil, attributes: {}, activator: Navigator::TagActivator.new @name = String name @content = content @attributes = attributes.with_indifferent_access @activator = activator end # rubocop:enable Metrics/ParameterLists def prefix = ["<#{name}", format_attributes, ">"].compact.join def computed_content = self.class.names_without_suffix.include?(name) ? nil : content def suffix = self.class.names_without_suffix.include?(name) ? nil : "</#{name}>" def render = [prefix, computed_content, suffix].compact.join private attr_reader :attributes, :activator def expand_data_attributes! attrs return unless attrs.key? :data attrs.delete(:data).each { |key, value| attrs["data-#{key}"] = value } end def concatenate_attributes attrs activator.activate(attrs) .map { |key, value| %(#{key}="#{value}") } .join(" ") end def format_attributes attrs = attributes.clone expand_data_attributes! attrs attrs = concatenate_attributes attrs attrs.empty? ? nil : " #{attrs}"
Source
# File lib/navigator/tag.rb, line 11 def initialize name, content = nil, attributes: {}, activator: Navigator::TagActivator.new @name = String name @content = content @attributes = attributes.with_indifferent_access @activator = activator end
rubocop:disable Metrics/ParameterLists
Public Instance Methods
Source
# File lib/navigator/tag.rb, line 21 def computed_content = self.class.names_without_suffix.include?(name) ? nil : content def suffix = self.class.names_without_suffix.include?(name) ? nil : "</#{name}>" def render = [prefix, computed_content, suffix].compact.join private attr_reader :attributes, :activator def expand_data_attributes! attrs return unless attrs.key? :data attrs.delete(:data).each { |key, value| attrs["data-#{key}"] = value } end def concatenate_attributes attrs activator.activate(attrs) .map { |key, value| %(#{key}="#{value}") } .join(" ") end def format_attributes attrs = attributes.clone expand_data_attributes! attrs attrs = concatenate_attributes attrs attrs.empty? ? nil : " #{attrs}" end end
Source
# File lib/navigator/tag.rb, line 37 def concatenate_attributes attrs activator.activate(attrs) .map { |key, value| %(#{key}="#{value}") } .join(" ") end
Source
# File lib/navigator/tag.rb, line 31 def expand_data_attributes! attrs return unless attrs.key? :data attrs.delete(:data).each { |key, value| attrs["data-#{key}"] = value } end
Source
# File lib/navigator/tag.rb, line 43 def format_attributes attrs = attributes.clone expand_data_attributes! attrs attrs = concatenate_attributes attrs attrs.empty? ? nil : " #{attrs}" end
Source
# File lib/navigator/tag.rb, line 19 def prefix = ["<#{name}", format_attributes, ">"].compact.join def computed_content = self.class.names_without_suffix.include?(name) ? nil : content def suffix = self.class.names_without_suffix.include?(name) ? nil : "</#{name}>" def render = [prefix, computed_content, suffix].compact.join private attr_reader :attributes, :activator def expand_data_attributes! attrs return unless attrs.key? :data attrs.delete(:data).each { |key, value| attrs["data-#{key}"] = value } end def concatenate_attributes attrs activator.activate(attrs) .map { |key, value| %(#{key}="#{value}") } .join(" ") end def format_attributes attrs = attributes.clone expand_data_attributes! attrs attrs = concatenate_attributes attrs attrs.empty? ? nil : " #{attrs}" end
rubocop:enable Metrics/ParameterLists
Source
# File lib/navigator/tag.rb, line 25 def render = [prefix, computed_content, suffix].compact.join private attr_reader :attributes, :activator def expand_data_attributes! attrs return unless attrs.key? :data attrs.delete(:data).each { |key, value| attrs["data-#{key}"] = value } end def concatenate_attributes attrs activator.activate(attrs) .map { |key, value| %(#{key}="#{value}") } .join(" ") end def format_attributes attrs = attributes.clone expand_data_attributes! attrs attrs = concatenate_attributes attrs attrs.empty? ? nil : " #{attrs}" end end
Source
# File lib/navigator/tag.rb, line 23 def suffix = self.class.names_without_suffix.include?(name) ? nil : "</#{name}>" def render = [prefix, computed_content, suffix].compact.join private attr_reader :attributes, :activator def expand_data_attributes! attrs return unless attrs.key? :data attrs.delete(:data).each { |key, value| attrs["data-#{key}"] = value } end def concatenate_attributes attrs activator.activate(attrs) .map { |key, value| %(#{key}="#{value}") } .join(" ") end def format_attributes attrs = attributes.clone expand_data_attributes! attrs attrs = concatenate_attributes attrs attrs.empty? ? nil : " #{attrs}" end end end