module Middleman::KSS::Helpers
Constants
- DEFAULT_STYLEGUIDE_BLOCK_FILE
Public Instance Methods
get_styleguide()
click to toggle source
# File lib/middleman-kss/extension.rb, line 79 def get_styleguide # Parse the KSS style guide once per request (because it probably changes every request) unless request.has_key?(:styleguide) extension_options = ::Middleman::KSS.options request[:styleguide] = ::Kss::Parser.new(File.join(self.source_dir, extension_options[:kss_dir])) end return request[:styleguide] end
kss_h(text)
click to toggle source
Simple HTML escape helper
# File lib/middleman-kss/extension.rb, line 69 def kss_h(text) Rack::Utils.escape_html(text) end
kss_markdown(input)
click to toggle source
Markdown in KSS
# File lib/middleman-kss/extension.rb, line 74 def kss_markdown(input) markdown = ::Redcarpet::Markdown.new(::Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true) markdown.render(input) end
styleblock(tile, options = {})
click to toggle source
Renders a styleblock with or without styleguide information.
@param [String] tile
Name of the style tile file to render.
@param [Hash] options
Options for rendering.
@option options [String] :section
KSS section number (e.g. "1.1") for fetching the styleguide information.
@return [String] Generated HTML.
# File lib/middleman-kss/extension.rb, line 44 def styleblock(tile, options = {}) tile_file = "_#{tile}.html.erb" tile_path = File.join(self.source_dir, "styleblocks", tile_file) tile_template = ::Tilt.new(tile_path) @block_html = tile_template.render(self) @styleguide = self.get_styleguide if options.has_key?(:section) @section = @styleguide.section(options[:section]) raise "Section must have a description. Section #{options[:section]} does not have one or section does not exist." if @section.description.blank? end if @section # Render the styleguide block styleguide_block_path = File.join(File.dirname(__FILE__), DEFAULT_STYLEGUIDE_BLOCK_FILE) template = ::Tilt.new(styleguide_block_path) return template.render(self) else # Render just the HTML without the $modifier_class thingies return @block_html.gsub('$modifier_class', '').gsub(' class=""', '').prepend('<div class="styleguide-styleblock">') << '</div>' end end