class GrantFront::Engine

Attributes

request[RW]
tree[RW]

Private Class Methods

call(env) click to toggle source
# File lib/grant-front/engine.rb, line 68
def call(env)
  prototype.call(env)
end
prototype() click to toggle source
# File lib/grant-front/engine.rb, line 64
def prototype
  @prototype ||= new
end

Public Instance Methods

call(env) click to toggle source
# File lib/grant-front/engine.rb, line 10
def call(env)
  @request = Rack::Request.new(env)

  status = 200
  headers = {'Content-Type' => 'text/html'}
  body = ERB.new(application_template).result(binding)

  [status, headers, [body]]
end

Private Instance Methods

application_template() click to toggle source
# File lib/grant-front/engine.rb, line 55
def application_template
  root_path = Pathname.new(File.expand_path('..', File.dirname(__FILE__)))
  templates_path = File.join(root_path, 'templates')
  application_layout = File.expand_path('application.html.erb', File.join(templates_path, 'layouts'))
  File.read(application_layout)
end
policies_tag() click to toggle source
# File lib/grant-front/engine.rb, line 25
def policies_tag
  raw = ""
  policies = GrantFront::Policy.all(rake: false)

  raw += "<div><ul>"
  raw += policies.map do |policy|
    raw = "<li"
    if '/' + policy.urn == request.path_info
      raw += " class='active'"
    end
    raw += "><a href=#{request.script_name}/#{policy.urn}>#{policy.name}</a>"
    raw += "</li>"
  end.join("\n")
  raw += "</ul></div>"

  raw
end
policy_tag() click to toggle source
# File lib/grant-front/engine.rb, line 43
def policy_tag
  policies = GrantFront::Policy.all(rake: false)
  classes = policies.inject([]) do |arr, policy|
    arr << policy.klass if '/' + policy.urn == request.path_info
    arr
  end
  classes = nil if classes.count == 0

  text = Diagram.new(rake: false, classes: classes).create
  Kramdown::Document.new(text).to_html
end