Top Level Namespace
Defined Under Namespace
Modules: Broadway
Classes: Array, Date, Hash, String
Instance Method Summary
collapse
Instance Method Details
#Broadway(*args, &block) ⇒ Object
87
88
89
|
# File 'lib/broadway.rb', line 87
def Broadway(*args, &block)
Broadway.define!(*args, &block)
end
|
#c(path) ⇒ Object
19
20
21
|
# File 'lib/broadway/sinatra/app.rb', line 19
def c(path)
site.setting(path)
end
|
#error?(response, path, whiny = true) ⇒ Boolean
9
10
11
12
13
14
15
16
|
# File 'lib/broadway/run.rb', line 9
def error?(response, path, whiny = true)
if !response.is_a?(Net::HTTPSuccess)
raise message if whiny
puts "Error at '#{path}': #{response.to_s}"
return true
end
false
end
|
#render_path(site, http, path, post = nil) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/broadway/run.rb', line 42
def render_path(site, http, path, post = nil)
date = "2010-01-01"
response = http.get(path)
write_to = File.expand_path(File.join(site.setting(:destination), path).squeeze("/"))
puts "get #{path}"
return if error?(response, path, false)
return if post && sitemap?(response.body, post)
body = response.body
content = ""
if path == "/"
name = "index.html"
else
FileUtils.mkdir_p(write_to)
name = File.join(write_to, "#{date}-index.html")
content << "---\n"
content << "categories: [#{path.split("/").delete_if {|node| node.blank?}.join(", ")}]\n"
content << "---\n"
end
content << body
File.open(name, "w") { |f| f.write(content) }
end
|
#site ⇒ Object
must define the SITE constant
15
16
17
|
# File 'lib/broadway/sinatra/app.rb', line 15
def site
SITE
end
|
#sitemap?(body, post) ⇒ Boolean
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/broadway/run.rb', line 18
def sitemap?(body, post)
return false if post.path !~ /^\/sitemap/
attributes = {
:version => "2.0",
"xmlns:html" => "http://www.w3.org/TR/REC-html40",
"xmlns:sitemap" => "http://www.sitemaps.org/schemas/sitemap/0.9",
"xmlns:xsl" => "http://www.w3.org/1999/XSL/Transform"
}
builder = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
xml.stylesheet(attributes) do
xml.parent.namespace = xml.parent.namespace_definitions.last
xml["xsl"].output(:method => "html", :version => "1.0", :encoding => "UTF-8", :indent => "yes")
xml["xsl"].template(:match => "/") do
xml << body.gsub(/\<\!doctype[^>]+\>/i, "").gsub(/^/, " ")
end
end
end
content = builder.to_xml
name = File.join("stylesheets/sitemap.xsl")
File.open(name, "w") { |f| f.write(content) }
return true
end
|