class Govuk::DummyContentStore::Index
Attributes
example_repository[R]
Public Class Methods
new(example_repository)
click to toggle source
# File lib/govuk/dummy_content_store/index.rb, line 10 def initialize(example_repository) @example_repository = example_repository end
Public Instance Methods
call(env)
click to toggle source
# File lib/govuk/dummy_content_store/index.rb, line 14 def call(env) if env["PATH_INFO"] == "/" render_index else [404, {}, ["Not found"]] end end
Private Instance Methods
load_template(name)
click to toggle source
# File lib/govuk/dummy_content_store/index.rb, line 34 def load_template(name) File.read(File.dirname(__FILE__) + "/templates/#{name}", encoding: "UTF-8") end
render_index()
click to toggle source
# File lib/govuk/dummy_content_store/index.rb, line 23 def render_index status = 200 body = render_template("index.html.erb", examples: example_repository.all) headers = { 'Content-Type' => 'text/html; charset=utf-8', 'Content-Length' => body.bytesize.to_s, 'Cache-control' => 'no-cache' } [status, headers, [body]] end
render_template(template_name, vars)
click to toggle source
# File lib/govuk/dummy_content_store/index.rb, line 46 def render_template(template_name, vars) template = load_template(template_name) ERB.new(template).result(CleanBinding.new(vars).binding) end