Top Level Namespace
Defined Under Namespace
Modules: Broadway
Classes: Array, Date, Hash
Instance Method Summary
collapse
Instance Method Details
#c(path) ⇒ Object
61
62
63
64
65
|
# File 'lib/broadway/sinatra/base.rb', line 61
def c(path)
result = site.config
path.to_s.split(".").each { |node| result = result[node.to_sym] if result }
result.nil? ? [] : result
end
|
#content_path(content, version, action) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/broadway/sinatra/base.rb', line 67
def content_path(content, version, action)
path = File.join(content.dir, action).squeeze("/")
exists = false
extensions = %w(html haml erb html.haml html.erb)
target_path = File.join(site.config[:source], path)
extensions.each do |ext|
exists = true if File.exists?("#{target_path}.#{ext}")
end
return path if exists
checked = [target_path]
path = target_path = File.join(theme_path(version), content.layout, action).squeeze("/")
exists = false
extensions.each do |ext|
exists = true if File.exists?(File.join(site.config[:source], "#{target_path}.#{ext}"))
end
return path if exists
return File.join(theme_path(version), "index") if content.url == "/"
checked << target_path
puts "Couldn't find any paths for #{content.class.to_s.downcase.split(":").last} '#{content.url}': #{checked.inspect}"
return nil
end
|
#default_locals(locals = {}) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/broadway/sinatra/base.rb', line 19
def default_locals(locals = {})
{
:environment => Sinatra::Application.environment,
:theme_version => "main"
}.merge(locals)
end
|
#default_options(options = {}) ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/broadway/sinatra/base.rb', line 26
def default_options(options = {})
if params.has_key?("layout") and params["layout"] == false
options[:layout] = false
else
options[:layout] = !request.xhr?
end
options
end
|
#files(path, from = __FILE__, &block) ⇒ Object
1
2
3
|
# File 'lib/broadway/base.rb', line 1
def files(path, from = __FILE__, &block)
Dir.glob(File.join(File.dirname(from), path)) {|file| yield file}
end
|
#page_path(page, version) ⇒ Object
53
54
55
|
# File 'lib/broadway/sinatra/base.rb', line 53
def page_path(page, version)
content_path(page, version, "index")
end
|
#pages ⇒ Object
44
45
46
|
# File 'lib/broadway/sinatra/base.rb', line 44
def pages
Dir.entries("public")
end
|
#post_path(post, version) ⇒ Object
57
58
59
|
# File 'lib/broadway/sinatra/base.rb', line 57
def post_path(post, version)
content_path(post, version, "show")
end
|
#require_local(path, from = __FILE__) ⇒ Object
5
6
7
|
# File 'lib/broadway/base.rb', line 5
def require_local(path, from = __FILE__)
files(path, from) {|file| require file}
end
|
#site ⇒ Object
15
16
17
|
# File 'lib/broadway/sinatra/base.rb', line 15
def site
@site
end
|
#theme_path(version = "main") ⇒ Object
35
36
37
|
# File 'lib/broadway/sinatra/base.rb', line 35
def theme_path(version = "main")
File.join(site.config[:theme_path], site.config[:theme], version)
end
|
#theme_versions ⇒ Object
“main” is the default, so remove it
40
41
42
|
# File 'lib/broadway/sinatra/base.rb', line 40
def theme_versions
site.config[:theme_versions]
end
|