Class: Buttless
- Inherits:
-
Object
- Object
- Buttless
- Defined in:
- lib/buttless.rb
Instance Method Summary collapse
- #config ⇒ Object
- #example(name) ⇒ Object
- #generate_html(with_base = false) ⇒ Object
- #host ⇒ Object
-
#initialize(home_dir, host = "http://127.0.0.1:9292") ⇒ Buttless
constructor
A new instance of Buttless.
- #reload_data ⇒ Object
Constructor Details
#initialize(home_dir, host = "http://127.0.0.1:9292") ⇒ Buttless
Returns a new instance of Buttless.
6 7 8 9 |
# File 'lib/buttless.rb', line 6 def initialize(home_dir, host="http://127.0.0.1:9292") @home_dir = home_dir @host = host end |
Instance Method Details
#config ⇒ Object
11 12 13 14 |
# File 'lib/buttless.rb', line 11 def config reload_data() @config end |
#example(name) ⇒ Object
40 41 42 43 44 |
# File 'lib/buttless.rb', line 40 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
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/buttless.rb', line 20 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(={}), 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 |
#host ⇒ Object
16 17 18 |
# File 'lib/buttless.rb', line 16 def host @host end |
#reload_data ⇒ Object
34 35 36 37 |
# File 'lib/buttless.rb', line 34 def reload_data @config = YAML::load(File.open("#{@home_dir}/config.yaml")) @db = YAML::load(File.open("#{@home_dir}/database.yaml")) end |