Class: LivingStyleGuide::RedcarpetHTML

Inherits:
Redcarpet::Render::HTML
  • Object
show all
Defined in:
lib/livingstyleguide/markdown_extensions.rb

Instance Method Summary collapse

Constructor Details

#initialize(document, options = {}) ⇒ RedcarpetHTML

Returns a new instance of RedcarpetHTML.



17
18
19
20
21
22
23
24
# File 'lib/livingstyleguide/markdown_extensions.rb', line 17

def initialize(document, options = {})
  @options = options
  @options[:prefix] ||= "lsg-"
  @document = document
  @header = nil
  @ids = {}
  super @options
end

Instance Method Details

#block_code(code, language) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/livingstyleguide/markdown_extensions.rb', line 50

def block_code(code, language)
  language = language.to_s.strip.to_sym
  language = @options[:default_language] if language == :""
  document = Document.new(livingstyleguide: @document) { code }
  document.id = document_id
  document.type = if language == :example
                  then @document.defaults[:global][:type]
                  else language
                  end
  document.template = template_for(language)
  document.render(@document.scope)
end

#codespan(code) ⇒ Object



63
64
65
66
67
# File 'lib/livingstyleguide/markdown_extensions.rb', line 63

def codespan(code)
  code = ERB::Util.html_escape(code)
  class_name = "#{@options[:prefix]}code-span #{@options[:prefix]}code"
  %Q(<code class="#{class_name}">#{code}</code>)
end

#header(text, header_level) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/livingstyleguide/markdown_extensions.rb', line 26

def header(text, header_level)
  @header = id = slug(text)
  class_names = %w(page-title headline sub-headline sub-sub-headline)
  class_name = "#{@options[:prefix]}#{class_names[header_level]}"
  header_level += 1
  %Q(<h#{header_level} class="#{class_name}" id="#{id}">) +
    %Q(<a class="lsg-anchor" href="##{id}"></a>#{text}</h#{header_level}>\n)
end

#list(contents, list_type) ⇒ Object



39
40
41
42
43
# File 'lib/livingstyleguide/markdown_extensions.rb', line 39

def list(contents, list_type)
  tag_name = "#{list_type.to_s[0, 1]}l"
  class_name = "#{@options[:prefix]}#{list_type}-list"
  %Q(<#{tag_name} class="#{class_name}">\n#{contents}</#{tag_name}>\n)
end

#list_item(text, list_type) ⇒ Object



45
46
47
48
# File 'lib/livingstyleguide/markdown_extensions.rb', line 45

def list_item(text, list_type)
  class_name = "#{@options[:prefix]}#{list_type}-list-item"
  %Q(<li class="#{class_name}">#{text.strip}</li>\n)
end

#paragraph(text) ⇒ Object



35
36
37
# File 'lib/livingstyleguide/markdown_extensions.rb', line 35

def paragraph(text)
  %Q(<p class="#{@options[:prefix]}paragraph">#{text}</p>\n)
end