broadway 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -1
- data/lib/broadway/mixins/taggable.rb +3 -3
- data/lib/broadway/resources/asset.rb +5 -1
- data/lib/broadway/resources/configuration.rb +0 -1
- data/lib/broadway/resources/file.rb +1 -1
- data/lib/broadway/resources/post.rb +41 -0
- data/lib/broadway/resources/site.rb +8 -0
- data/lib/broadway/run.rb +85 -0
- data/lib/broadway/sinatra/helpers/collection_helper.rb +8 -3
- data/lib/broadway/sinatra/processor.rb +30 -1
- metadata +7 -6
data/README.markdown
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
<h1>
|
2
2
|
<span>Broadway</span>
|
3
|
+
<!--
|
3
4
|
<span><img src="http://viatropos.github.com/broadway/favicon.png"/></span>
|
5
|
+
-->
|
4
6
|
</h1>
|
5
7
|
|
6
8
|
Pluggable, portable, framework-friendly static site generator. Setting the Stage for the Ruby CMS.
|
@@ -108,7 +110,7 @@ The `Configuration` object is defined from `_config.yml` in the Broadway Site ro
|
|
108
110
|
|
109
111
|
## Context
|
110
112
|
|
111
|
-
There are plenty of static site generators out there: [Jekyll](http://github.com/mojombo/jekyll), [Webby](http://github.com/TwP/webby), [Nanoc](http://github.com/ddfreyne/nanoc), [StaticMatic](http://github.com/staticmatic/staticmatic), [Middleman](http://github.com/tdreyno/middleman), [Mercury](http://github.com/jackhq/mercury), [Frank](http://github.com/blahed/frank), [DynamicMatic](http://github.com/nex3/dynamicmatic), [WebGen](http://github.com/gettalong/webgen), [Pekky](http://github.com/lukesutton/pekky), [Awestruct](http://github.com/bobmcwhirter/awestruct), [Massimo](http://github.com/petebrowne/massimo)... The problem with them is that they are completely separate frameworks from Sinatra and Rails. They're not meant to be used with either of those. It's a lot of work to integrate them.
|
113
|
+
There are plenty of static site generators out there: [Jekyll](http://github.com/mojombo/jekyll), [Webby](http://github.com/TwP/webby), [Nanoc](http://github.com/ddfreyne/nanoc), [StaticMatic](http://github.com/staticmatic/staticmatic), [Middleman](http://github.com/tdreyno/middleman), [Mercury](http://github.com/jackhq/mercury), [Frank](http://github.com/blahed/frank), [DynamicMatic](http://github.com/nex3/dynamicmatic), [WebGen](http://github.com/gettalong/webgen), [Pekky](http://github.com/lukesutton/pekky), [Awestruct](http://github.com/bobmcwhirter/awestruct), [Massimo](http://github.com/petebrowne/massimo), [Toto](http://cloudhead.io/toto)... The problem with them is that they are completely separate frameworks from Sinatra and Rails. They're not meant to be used with either of those. It's a lot of work to integrate them.
|
112
114
|
|
113
115
|
Broadway makes Rails and Sinatra static-compatible.
|
114
116
|
|
@@ -10,11 +10,11 @@ module Broadway
|
|
10
10
|
# tags can be stored under multiple contexts
|
11
11
|
# default is "tags" (use "categories" or whatever else you want)
|
12
12
|
def tags(context = "tags")
|
13
|
-
|
13
|
+
if @tags.blank?
|
14
14
|
@tags = tag_hash(self.data["tags"] || [])
|
15
15
|
end
|
16
|
-
|
17
|
-
@tags[context.to_s]
|
16
|
+
@tags["tags"] ||= []
|
17
|
+
@tags[context.to_s]
|
18
18
|
end
|
19
19
|
|
20
20
|
def tags=(value)
|
@@ -13,7 +13,7 @@ module Broadway
|
|
13
13
|
self.resource = resource
|
14
14
|
self.name = name
|
15
15
|
self.data = options.recursively_symbolize_keys!
|
16
|
-
self.path = options.delete(:path)
|
16
|
+
self.path = options.delete(:path) || options.delete(:src) || options.delete(:url) || options.delete(:href)
|
17
17
|
options.each do |k,v|
|
18
18
|
self.send("#{k}=", v) if self.respond_to?(k)
|
19
19
|
end
|
@@ -21,6 +21,10 @@ module Broadway
|
|
21
21
|
self.title ||= Broadway::File.file_name(self.path).titleize
|
22
22
|
end
|
23
23
|
|
24
|
+
alias url path
|
25
|
+
alias href path
|
26
|
+
alias src path
|
27
|
+
|
24
28
|
def site
|
25
29
|
resource.site
|
26
30
|
end
|
@@ -57,7 +57,6 @@ module Broadway
|
|
57
57
|
# then, we need to know where to look for _settings.yml
|
58
58
|
source = overrides[:source] || DEFAULTS[:source]
|
59
59
|
settings_file = overrides[:settings] || DEFAULTS[:settings]
|
60
|
-
settings_file = ::File.join(source, settings_file) unless ::File.exists?(settings_file)
|
61
60
|
# Get configuration from <source>/_config.yml
|
62
61
|
begin
|
63
62
|
settings = YAML.load_file(settings_file).recursively_symbolize_keys!
|
@@ -54,7 +54,7 @@ module Broadway
|
|
54
54
|
content = read(attribute)
|
55
55
|
case extension.to_s
|
56
56
|
when "markdown", "md"
|
57
|
-
content = RDiscount.new(content).to_html
|
57
|
+
content = RDiscount.new(content, :filter_html, :smart).to_html
|
58
58
|
when "textile"
|
59
59
|
content = RedCloth.new(content).to_html
|
60
60
|
end
|
@@ -59,5 +59,46 @@ module Broadway
|
|
59
59
|
@description
|
60
60
|
end
|
61
61
|
|
62
|
+
def self_and_siblings
|
63
|
+
if parent
|
64
|
+
parent.children.blank? ? nil : parent.children
|
65
|
+
else
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def submenu
|
71
|
+
return nil if data["submenu"].blank?
|
72
|
+
data["submenu"].map do |path|
|
73
|
+
site.find_post_by_path(path)
|
74
|
+
end.compact
|
75
|
+
end
|
76
|
+
|
77
|
+
def subpages
|
78
|
+
(self_and_siblings || submenu || children).sort do |a, b|
|
79
|
+
if a.data["position"] && b.data["position"]
|
80
|
+
a.data["position"].to_i <=> b.data["position"]
|
81
|
+
else
|
82
|
+
a <=> b
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def gallery
|
88
|
+
data["gallery"] || nil
|
89
|
+
end
|
90
|
+
|
91
|
+
def menu_title
|
92
|
+
data["menu_title"] || title
|
93
|
+
end
|
94
|
+
|
95
|
+
def subtitle
|
96
|
+
data["subtitle"] || nil
|
97
|
+
end
|
98
|
+
|
99
|
+
def parent_path
|
100
|
+
("/" + categories.join("/")).squeeze("/")
|
101
|
+
end
|
102
|
+
|
62
103
|
end
|
63
104
|
end
|
@@ -15,6 +15,10 @@ module Broadway
|
|
15
15
|
processor.build
|
16
16
|
end
|
17
17
|
|
18
|
+
def assets
|
19
|
+
posts.map(&:assets).flatten.uniq
|
20
|
+
end
|
21
|
+
|
18
22
|
def generate!
|
19
23
|
processor.generate
|
20
24
|
end
|
@@ -27,6 +31,10 @@ module Broadway
|
|
27
31
|
settings[:url] || "http://localhost"
|
28
32
|
end
|
29
33
|
|
34
|
+
def production_url
|
35
|
+
settings[:production_url]
|
36
|
+
end
|
37
|
+
|
30
38
|
def index_path
|
31
39
|
settings[:index_path]
|
32
40
|
end
|
data/lib/broadway/run.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'broadway'
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
this = File.expand_path(File.dirname(__FILE__))
|
7
|
+
site = Broadway.build(:source => "#{this}/../_content", :settings => "#{this}/_config.yml")
|
8
|
+
|
9
|
+
def error?(response, path, whiny = true)
|
10
|
+
if !response.is_a?(Net::HTTPSuccess)
|
11
|
+
raise message if whiny
|
12
|
+
puts "Error at '#{path}': #{response.to_s}"
|
13
|
+
return true
|
14
|
+
end
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
def sitemap?(body, post)
|
19
|
+
return false if post.path !~ /^\/sitemap/
|
20
|
+
attributes = {
|
21
|
+
:version => "2.0",
|
22
|
+
"xmlns:html" => "http://www.w3.org/TR/REC-html40",
|
23
|
+
"xmlns:sitemap" => "http://www.sitemaps.org/schemas/sitemap/0.9",
|
24
|
+
"xmlns:xsl" => "http://www.w3.org/1999/XSL/Transform"
|
25
|
+
}
|
26
|
+
builder = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
|
27
|
+
xml.stylesheet(attributes) do
|
28
|
+
xml.parent.namespace = xml.parent.namespace_definitions.last
|
29
|
+
xml["xsl"].output(:method => "html", :version => "1.0", :encoding => "UTF-8", :indent => "yes")
|
30
|
+
xml["xsl"].template(:match => "/") do
|
31
|
+
xml << body.gsub(/\<\!doctype[^>]+\>/i, "").gsub(/^/, " ")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
content = builder.to_xml
|
36
|
+
|
37
|
+
name = File.join("stylesheets/sitemap.xsl")
|
38
|
+
File.open(name, "w") { |f| f.write(content) }
|
39
|
+
return true
|
40
|
+
end
|
41
|
+
|
42
|
+
def render_path(site, http, path, post = nil)
|
43
|
+
date = "2010-01-01"
|
44
|
+
response = http.get(path)
|
45
|
+
write_to = File.expand_path(File.join(site.setting(:destination), path).squeeze("/"))
|
46
|
+
# if the file doesn't exist or is not rendered correctly
|
47
|
+
puts "get #{path}"
|
48
|
+
return if error?(response, path, false)
|
49
|
+
return if post && sitemap?(response.body, post)
|
50
|
+
body = response.body
|
51
|
+
content = ""
|
52
|
+
if path == "/"
|
53
|
+
name = "index.html"
|
54
|
+
else
|
55
|
+
FileUtils.mkdir_p(write_to)
|
56
|
+
name = File.join(write_to, "#{date}-index.html")
|
57
|
+
content << "---\n"
|
58
|
+
content << "categories: [#{path.split("/").delete_if {|node| node.blank?}.join(", ")}]\n"
|
59
|
+
content << "---\n"
|
60
|
+
end
|
61
|
+
content << body
|
62
|
+
File.open(name, "w") { |f| f.write(content) }
|
63
|
+
end
|
64
|
+
|
65
|
+
url = URI.parse("http://localhost:4567")
|
66
|
+
#Time.now.strftime("%Y-%m-%d")
|
67
|
+
begin
|
68
|
+
Net::HTTP.start(url.host, url.port) do |http|
|
69
|
+
site.posts.reverse.each do |post|
|
70
|
+
render_path(site, http, post.path, post)
|
71
|
+
end
|
72
|
+
render_path(site, http, "/about")
|
73
|
+
render_path(site, http, "/tags")
|
74
|
+
site.tags.each do |tag, posts|
|
75
|
+
begin
|
76
|
+
render_path(site, http, "/tags/#{tag}")
|
77
|
+
rescue Exception => e
|
78
|
+
puts "#{tag}: #{e.inspect}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
rescue Exception => e
|
83
|
+
puts e.inspect
|
84
|
+
raise "Make sure you've started the server, run: 'ruby app.rb'"
|
85
|
+
end
|
@@ -20,12 +20,17 @@ module Broadway
|
|
20
20
|
def row_for(array, options = {}, &block)
|
21
21
|
return "" if array.empty?
|
22
22
|
array.each_with_index do |node, i|
|
23
|
-
attributes = options.has_key?(:li_attributes) ? options[:li_attributes] : {}
|
23
|
+
attributes = (options.has_key?(:li_attributes) ? options[:li_attributes] : {}).dup
|
24
24
|
attributes[:class] ||= ""
|
25
25
|
if i == 0 and options.has_key?(:first)
|
26
|
-
attributes[:class] << "#{options[:first]}"
|
26
|
+
attributes[:class] << " #{options[:first]}"
|
27
27
|
elsif i == array.length - 1 and options.has_key?(:last)
|
28
|
-
attributes[:class] << "#{options[:last]}"
|
28
|
+
attributes[:class] << " #{options[:last]}"
|
29
|
+
end
|
30
|
+
if attributes[:class].blank?
|
31
|
+
attributes.delete(:class)
|
32
|
+
else
|
33
|
+
attributes[:class].squeeze!(" ")
|
29
34
|
end
|
30
35
|
haml_tag :li, attributes do
|
31
36
|
if block_given?
|
@@ -35,10 +35,13 @@ module Broadway
|
|
35
35
|
requests
|
36
36
|
end
|
37
37
|
|
38
|
+
protected
|
39
|
+
|
38
40
|
def requests
|
39
41
|
begin
|
40
42
|
request
|
41
43
|
rescue Exception => e
|
44
|
+
puts e.inspect
|
42
45
|
requests # in case connection breaks
|
43
46
|
#raise "Make sure you've started the server, run: 'ruby app.rb'"
|
44
47
|
end
|
@@ -64,7 +67,9 @@ module Broadway
|
|
64
67
|
# if the file doesn't exist or is not rendered correctly
|
65
68
|
return if error?(response, path, false)
|
66
69
|
#return if sitemap?(response.body, post)
|
67
|
-
|
70
|
+
|
71
|
+
body = absolute!(response.body)
|
72
|
+
|
68
73
|
content = ""
|
69
74
|
if path == "/"
|
70
75
|
name = "index.html"
|
@@ -79,6 +84,30 @@ module Broadway
|
|
79
84
|
puts "done... #{path}"
|
80
85
|
::File.open(name, "w") { |f| f.write(content) }
|
81
86
|
end
|
87
|
+
|
88
|
+
def absolute!(body)
|
89
|
+
raise "set :production_url in _config.yml" if site.production_url.blank?
|
90
|
+
base = site.production_url.gsub(/\/$/, "") # no trailing slash
|
91
|
+
body.gsub!(/(src|href)=([\'\"])\//) do |match|
|
92
|
+
"#{$1}=#{$2}#{base}/"
|
93
|
+
end
|
94
|
+
body
|
95
|
+
=begin
|
96
|
+
html = Nokogiri::HTML(body)
|
97
|
+
html.css("a, link").each do |link|
|
98
|
+
if link["href"] =~ /^\//
|
99
|
+
link["href"] = base + link["href"]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
html.css("script, img, video").each do |src|
|
103
|
+
if src["src"] =~ /^\//
|
104
|
+
src["src"] = base + src["src"]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
html.to_html
|
109
|
+
=end
|
110
|
+
end
|
82
111
|
end
|
83
112
|
end
|
84
113
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: broadway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lance Pollard
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-24 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -48,7 +48,7 @@ dependencies:
|
|
48
48
|
version: 2.3.5
|
49
49
|
type: :runtime
|
50
50
|
version_requirements: *id002
|
51
|
-
description:
|
51
|
+
description: Pluggable, portable, framework-friendly static site generator. Setting the Stage for the Ruby CMS.
|
52
52
|
email: lancejpollard@gmail.com
|
53
53
|
executables: []
|
54
54
|
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- lib/broadway/resources/post.rb
|
92
92
|
- lib/broadway/resources/site.rb
|
93
93
|
- lib/broadway/resources/slug.rb
|
94
|
+
- lib/broadway/run.rb
|
94
95
|
- lib/broadway/sinatra/app.rb
|
95
96
|
- lib/broadway/sinatra/helpers/collection_helper.rb
|
96
97
|
- lib/broadway/sinatra/helpers/partial_helper.rb
|
@@ -133,6 +134,6 @@ rubyforge_project: broadway
|
|
133
134
|
rubygems_version: 1.3.7
|
134
135
|
signing_key:
|
135
136
|
specification_version: 3
|
136
|
-
summary: Pluggable, portable, framework-friendly Ruby Static Site Generator.
|
137
|
+
summary: Pluggable, portable, framework-friendly Ruby Static Site Generator.
|
137
138
|
test_files: []
|
138
139
|
|