Module: Hologram::CodeExampleRenderer

Defined in:
lib/hologram/code_example_renderer.rb,
lib/hologram/code_example_renderer/example.rb,
lib/hologram/code_example_renderer/factory.rb,
lib/hologram/code_example_renderer/template.rb

Defined Under Namespace

Classes: DefinitionProxy, Example, Factory, Template

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.path_to_custom_example_renderersObject

Returns the value of attribute path_to_custom_example_renderers.



64
65
66
# File 'lib/hologram/code_example_renderer.rb', line 64

def path_to_custom_example_renderers
  @path_to_custom_example_renderers
end

Class Method Details

.example_class_for(example_type) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/hologram/code_example_renderer.rb', line 20

def example_class_for(example_type)
  if example_types.has_key?(example_type)
    example_types[example_type][:example_class]
  else
    Example
  end
end

.example_template_for(example_type) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/hologram/code_example_renderer.rb', line 28

def example_template_for(example_type)
  if example_types.has_key?(example_type)
    example_types[example_type][:example_template]
  else
    [
      "<div class=\"codeBlock\">",
      "  <div class=\"highlight\">",
      "    <pre><%= code_example %></pre>",
      "  </div>",
      "</div>",
    ].join("\n")
  end
end

.load_renderers_and_templatesObject



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

def load_renderers_and_templates
  require 'hologram/code_example_renderer/factory'

  Dir[File.join(File.dirname(__FILE__), 'code_example_renderer', 'renderers', '*.rb')].each do |file|
    require file
  end

  if path_to_custom_example_renderers
    Dir[File.join(path_to_custom_example_renderers, '*.rb')].each do |file|
      require file
    end
  end
end

.register(example_type, args) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/hologram/code_example_renderer.rb', line 7

def register(example_type, args)
  puts "Adding renderer for #{example_type} examples"
  example_types[example_type] = {
    example_class: args[:example_class],
    example_template: args[:example_template],
    table_template: args[:table_template]
  }
end

.table_template_for(example_type) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/hologram/code_example_renderer.rb', line 42

def table_template_for(example_type)
  if example_types.has_key?(example_type)
    example_types[example_type][:table_template]
  else
    nil
  end
end

.unregister(example_type) ⇒ Object



16
17
18
# File 'lib/hologram/code_example_renderer.rb', line 16

def unregister(example_type)
  example_types.delete(example_type)
end