module Rapper::HtmlTags

HTML tag generators.

Public Instance Methods

css_tag( type, name ) click to toggle source

Build a CSS tag for an asset.

@param [Symbol] type Definition type.

@param [Symbol] name Name of the asset to build a ‘<link>` tag for.

@return [String] A ‘<link>` tag for the given asset in the configured HTML style.

# File lib/rapper/html_tags.rb, line 39
def css_tag( type, name )
  self.get_tag( CssTag, type, name )
end
js_tag( type, name ) click to toggle source

Build a JS tag for an asset.

@param [Symbol] type Definition type.

@param [Symbol] name Name of the asset to build a ‘<script>` tag for.

@return [String] A ‘<script>` tag for the given asset in the configured HTML style.

# File lib/rapper/html_tags.rb, line 27
def js_tag( type, name )
  self.get_tag( JsTag, type, name )
end
tag_method_for_type( type ) click to toggle source

@param [Symbol] type Definition type.

@return [Symbol] Tag type for the given definition type. One of ‘:css_tag` or `:js_tag`

# File lib/rapper/html_tags.rb, line 11
def tag_method_for_type( type )
  if @definitions[type].suffix =~ /css/
    :css_tag
  else
    :js_tag
  end
end
tag_paths( type, name ) click to toggle source

Same as ‘tag_files`, but includes version query string if needed.

# File lib/rapper/html_tags.rb, line 44
def tag_paths( type, name )
  definition = @definitions[type]
  if self.get_config( 'version' )
    version = definition.get_version( name )
    tag_files( type, name ).map{|path| "#{path}?v=#{version}"}
  else
    tag_files( type, name )
  end
end

Protected Instance Methods

get_tag( klass, type, name ) click to toggle source

Get the HTML for an asset.

@param [Rapper::HtmlTags::Tag] klass The HTML generator class to use.

@param [String] type Asset type.

@param [String] name Asset name.

# File lib/rapper/html_tags.rb, line 81
def get_tag( klass, type, name )
  definition = @definitions[type]
  style = self.get_config( 'tag_style' ).to_sym
  version = nil
  if self.get_config( 'version' )
    version = definition.get_version( name )
  end
  
  tag_files( type, name ).map do |path|
    klass.send( :for, path, version, style )
  end.join( "\n" )
end
tag_files( type, name ) click to toggle source

Get all paths for a given asset. If bundling is turned on, a one-item array is returned containing the path to the asset file. Otherwise, an array of all component paths for the asset are returned.

@param [Symbol] type Definition type.

@param [Symbol] name Name of the asset to get paths for.

@return [String<Array>] All files that comprise the given asset.

# File lib/rapper/html_tags.rb, line 65
def tag_files( type, name )
  definition = @definitions[type]
  if self.get_config( "bundle" )
    Array( definition.asset_path( name, definition.asset_tag_root ) )
  else
    definition.component_paths( name, definition.component_tag_root )
  end
end