Module: Middleman::KSS::Helpers
- Defined in:
- lib/middleman-kss/extension.rb
Constant Summary collapse
- DEFAULT_STYLEGUIDE_BLOCK_FILE =
'_styleguide_block.html.erb'
Instance Method Summary collapse
- #get_styleguide ⇒ Object
-
#kss_h(text) ⇒ Object
Simple HTML escape helper.
-
#kss_markdown(input) ⇒ Object
Markdown in KSS.
-
#styleblock(tile, options = {}) ⇒ String
Renders a styleblock with or without styleguide information.
Instance Method Details
#get_styleguide ⇒ Object
79 80 81 82 83 84 85 86 87 |
# 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) = ::Middleman::KSS. request[:styleguide] = ::Kss::Parser.new(File.join(self.source_dir, [:kss_dir])) end return request[:styleguide] end |
#kss_h(text) ⇒ Object
Simple HTML escape helper
69 70 71 |
# File 'lib/middleman-kss/extension.rb', line 69 def kss_h(text) Rack::Utils.escape_html(text) end |
#kss_markdown(input) ⇒ Object
Markdown in KSS
74 75 76 77 |
# 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 = {}) ⇒ String
Renders a styleblock with or without styleguide information.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/middleman-kss/extension.rb', line 44 def styleblock(tile, = {}) 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 .has_key?(:section) @section = @styleguide.section([:section]) raise "Section must have a description. Section #{[: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 |