class Rack::Usermanual

Constants

VERSION

Public Class Methods

new(app, options) click to toggle source
Calls superclass method
# 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

Public Instance Methods

get_feature(path, page) click to toggle source
# 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
h(text) click to toggle source
# File lib/rack/usermanual/app.rb, line 34
def h(text)
  Rack::Utils.escape_html(text)
end
humanize(word) click to toggle source
# File lib/rack/usermanual/app.rb, line 38
def humanize(word)
  word.capitalize.gsub(/[-_]/, ' ')
end
replace_start(sentence) click to toggle source
# File lib/rack/usermanual/app.rb, line 42
def replace_start(sentence)
  {
    /^given / => 'Assume ',
    /^but / => 'However, ',
    /^and / => ''
  }.each do |find, replace|
    sentence.sub!(find, replace)
  end
  sentence
end