Class: EngineOfWar::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/engine_of_war/page.rb

Constant Summary collapse

YAML_REGEXP =
/^(---\s*\n.*?\n?)^(---\s*$\n?)/m

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_path) ⇒ Page

Returns a new instance of Page.



6
7
8
9
10
11
12
# File 'lib/engine_of_war/page.rb', line 6

def initialize(request_path)
  @views_root    = EngineOfWar::App.settings.views
  @root          = EngineOfWar::App.settings.root
  @request_path  = normalize_path(request_path)
  @entire_source = File.read(template_path)
  @meta, @source = split_body
end

Instance Attribute Details

#metaObject (readonly)

Returns the value of attribute meta.



4
5
6
# File 'lib/engine_of_war/page.rb', line 4

def meta
  @meta
end

#request_pathObject (readonly)

Returns the value of attribute request_path.



4
5
6
# File 'lib/engine_of_war/page.rb', line 4

def request_path
  @request_path
end

#rootObject (readonly)

Returns the value of attribute root.



4
5
6
# File 'lib/engine_of_war/page.rb', line 4

def root
  @root
end

#sourceObject (readonly)

Returns the value of attribute source.



4
5
6
# File 'lib/engine_of_war/page.rb', line 4

def source
  @source
end

#views_rootObject (readonly)

Returns the value of attribute views_root.



4
5
6
# File 'lib/engine_of_war/page.rb', line 4

def views_root
  @views_root
end

Instance Method Details

#engineObject



22
23
24
# File 'lib/engine_of_war/page.rb', line 22

def engine
  template_path.split(".").last.to_sym
end

#github_edit_urlObject



26
27
28
29
30
31
32
# File 'lib/engine_of_war/page.rb', line 26

def github_edit_url
  snippet = EngineOfWar::App.settings.github_info
  if snippet.blank?
    raise RuntimeError, "We don't know your github info.  Fix with: EngineOfWar::App.set :github_info, 'foo/bar'"
  end
  "https://github.com/#{snippet}/edit/master#{template_path.sub(root, '')}"
end

#layoutObject



14
15
16
# File 'lib/engine_of_war/page.rb', line 14

def layout
  Layout.new(self).name
end

#urlObject



18
19
20
# File 'lib/engine_of_war/page.rb', line 18

def url
  request_path
end