Module: Sinatra::CqDocs::Helpers

Defined in:
lib/sinatra/cqdocs.rb

Instance Method Summary collapse

Instance Method Details

#classify(string) ⇒ Object



36
37
38
39
40
# File 'lib/sinatra/cqdocs.rb', line 36

def classify string
    result = string.downcase
    result = result.gsub(/([\W_]+)/, '-')
    result = result.gsub(/-\z/, '') 
end

#get_view_as_string(filename) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sinatra/cqdocs.rb', line 8

def get_view_as_string(filename)
    view = File.join(settings.cqdocs_view_path, filename)
    layout = File.join(settings.cqdocs_view_path, 'layouts/sample_markup.haml')
    data = ""
    f = File.open(view, "r")
    f.each_line do |line|
        data += line
    end
    return data
    return layout
end

#render_sample_code(options = {}, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sinatra/cqdocs.rb', line 20

def render_sample_code options={}, &block
    block = capture_haml(&block)
    capture_haml do
        haml_tag :section, :id => classify(options[:name]) do
            haml_tag :div, :class => "page-header" do
                haml_tag :h1, options[:name]
            end
            haml_tag :h2, "Example"
            haml_tag :p, options[:description]
            haml_tag :div, block, :class => "bs-docs-example"
            haml_tag :h2, "Markup"
            haml_tag :pre, html_escape(block), :class => "prettyprint linenums"
        end
    end
end