Class: Buttless

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

Instance Method Summary collapse

Constructor Details

#initialize(home_dir, host = "http://127.0.0.1:9292") ⇒ Buttless

Returns a new instance of Buttless.



8
9
10
11
# File 'lib/buttless.rb', line 8

def initialize(home_dir, host="http://127.0.0.1:9292")
  @home_dir = home_dir
  @host = host
end

Instance Method Details

#configObject



13
14
15
16
# File 'lib/buttless.rb', line 13

def config
  reload_data()
  @config
end

#example(name) ⇒ Object



42
43
44
45
46
# File 'lib/buttless.rb', line 42

def example(name)
  return "TODO" if name.nil?
  name = name.to_s
  File.open("#{@home_dir}/json_examples/#{name}.json".downcase,'r').read()
end

#generate_html(with_base = false) ⇒ Object



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

def generate_html(with_base=false)
  Dir.chdir(@home_dir)
  Dir.chdir('api-doc')
  @root_url = with_base ? "file://localhost#{Dir.pwd}/" : "./"
  reload_data()
  doc = Tilt.new("index.md.erb").render(self, :db=>@db, :helper=>Helper.new, :config=>@config)
  md = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(render_options={}), extensions={:tables=>true})
  #toc = Redcarpet::Markdown.new(Redcarpet::Render::HTML_TOC.new())
  @content = md.render(doc)

  @html = ERB.new(File.open('template.html.erb','r').read()).result(binding())
  @html = @html.gsub(/root_url/,@root_url)
end

#hostObject



18
19
20
# File 'lib/buttless.rb', line 18

def host
  @host
end

#reload_dataObject



36
37
38
39
# File 'lib/buttless.rb', line 36

def reload_data
  @config = YAML::load(File.open("#{@home_dir}/config.yaml"))
  @db = YAML::load(File.open("#{@home_dir}/database.yaml"))
end