Class: Moonrope::DocContext

Inherits:
Object
  • Object
show all
Defined in:
lib/moonrope/doc_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(generator, options = {}) ⇒ DocContext

Returns a new instance of DocContext.



6
7
8
9
10
# File 'lib/moonrope/doc_context.rb', line 6

def initialize(generator, options = {})
  @generator = generator
  @vars = options.delete(:vars) || {}
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/moonrope/doc_context.rb', line 36

def method_missing(name)
  if @vars.has_key?(name.to_sym)
    @vars[name.to_sym]
  else
    super
  end
end

Instance Attribute Details

#varsObject (readonly)

Returns the value of attribute vars.



4
5
6
# File 'lib/moonrope/doc_context.rb', line 4

def vars
  @vars
end

Instance Method Details

#asset_path(file) ⇒ Object



49
50
51
# File 'lib/moonrope/doc_context.rb', line 49

def asset_path(file)
  path("assets/" + file)
end

#baseObject



20
21
22
# File 'lib/moonrope/doc_context.rb', line 20

def base
  @generator.base
end

#friendly_type(type) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/moonrope/doc_context.rb', line 81

def friendly_type(type)
  if type.is_a?(Symbol)
    type.to_s.capitalize
  else
    type.to_s
  end
end

#full_prefixObject



53
54
55
# File 'lib/moonrope/doc_context.rb', line 53

def full_prefix
  "#{host}/#{prefix}/#{version}"
end

#git_versionObject



44
45
46
47
# File 'lib/moonrope/doc_context.rb', line 44

def git_version
  ENV["VDT_VERSION"] ||
  (`git rev-parse HEAD`.strip rescue nil)
end

#hostObject



24
25
26
# File 'lib/moonrope/doc_context.rb', line 24

def host
  @generator.host
end

#humanize(string) ⇒ Object



89
90
91
# File 'lib/moonrope/doc_context.rb', line 89

def humanize(string)
  string.to_s.gsub(/\_/, ' ')
end

#partial(name, attributes = {}) ⇒ Object



76
77
78
79
# File 'lib/moonrope/doc_context.rb', line 76

def partial(name, attributes = {})
  erb = self.class.new(@generator, @options.merge(:vars => attributes))
  erb.render(File.join(@generator.template_root_path, "_#{name}.erb"))
end

#path(file) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/moonrope/doc_context.rb', line 57

def path(file)
  depth = ((@options[:output_file] || '').split('/').size - 1).times.map { "../" }.join
  if file == :root
    file = depth + (@options[:welcome_file] || "welcome")
  else
    file = depth + file
  end

  if @options[:html_extensions] && !(file =~ /\.[a-z]+\z/)
    file = "#{file}.html"
  end

  file
end

#prefixObject



28
29
30
# File 'lib/moonrope/doc_context.rb', line 28

def prefix
  @generator.prefix
end

#render(template_file) ⇒ Object



72
73
74
# File 'lib/moonrope/doc_context.rb', line 72

def render(template_file)
  ERB.new(File.read(template_file), nil, '-').result(binding)
end

#set_active_nav(nav) ⇒ Object



16
17
18
# File 'lib/moonrope/doc_context.rb', line 16

def set_active_nav(nav)
  @vars[:active_nav] = nav
end

#set_page_title(title) ⇒ Object



12
13
14
# File 'lib/moonrope/doc_context.rb', line 12

def set_page_title(title)
  @vars[:page_title] = title
end

#versionObject



32
33
34
# File 'lib/moonrope/doc_context.rb', line 32

def version
  @generator.version
end