Class: Rack::Usermanual

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/rack/usermanual/app.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(app, options) ⇒ Usermanual

Returns a new instance of Usermanual.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rack/usermanual/app.rb', line 15

def initialize(app, options)
  super(app)
  @sections = options[:sections]
  @index = options[:index]

  layout = options[:layout] || 'views/layout.haml'

  path = ::File.dirname(layout)
  extension = ::File.extname(layout)
  file = ::File.basename(layout, extension)

  @render_options = {
    :layout => file.to_sym,
    :layout_options => { :views => path },
    :layout_engine => extension[1..-1].to_sym
  }
end

Instance Method Details

#get_feature(path, page) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rack/usermanual/app.rb', line 58

def get_feature(path, page)
  sio = StringIO.new
  json_formatter = Gherkin::Formatter::JSONFormatter.new(sio)
  parser = Gherkin::Parser::Parser.new(json_formatter)
  filepath = "#{path}/#{page}.feature"
  halt 404 unless ::File.exist?(filepath)
  raw = ::File.read(filepath)
  parser.parse(raw, uri, 0)
  json_formatter.done
  [raw, JSON.parse(sio.string)]
end