genit 1.0.1 → 2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/NEWS +12 -28
- data/README.markdown +6 -2
- data/Rakefile +1 -1
- data/TODO +177 -12
- data/VERSION +1 -1
- data/bin/genit +18 -20
- data/data/styles/screen.css +5 -9
- data/data/templates/main.html +0 -1
- data/lib/genit.rb +9 -4
- data/lib/genit/builders/body_link_builder.rb +8 -8
- data/lib/genit/builders/builder_base.rb +11 -11
- data/lib/genit/builders/head_link_builder.rb +8 -8
- data/lib/genit/builders/relativizer.rb +12 -12
- data/lib/genit/builders/script_builder.rb +7 -7
- data/lib/genit/documents/document_writer.rb +14 -14
- data/lib/genit/documents/fragment.rb +23 -22
- data/lib/genit/documents/xml_document.rb +5 -1
- data/lib/genit/project.rb +1 -0
- data/lib/genit/project/compiler.rb +54 -73
- data/lib/genit/project/page_compiler.rb +41 -41
- data/lib/genit/project/pages_finder.rb +6 -6
- data/lib/genit/project/project_creator.rb +116 -111
- data/lib/genit/project/root_cleaner.rb +31 -0
- data/lib/genit/project/rss_feed.rb +14 -14
- data/lib/genit/server.rb +2 -0
- data/lib/genit/server/server.rb +33 -0
- data/lib/genit/tags/class_fragment_tag.rb +2 -2
- data/lib/genit/tags/class_menu_tag.rb +2 -1
- data/lib/genit/tags/class_news_tag.rb +24 -24
- data/lib/genit/tags/class_pages_tag.rb +1 -1
- data/lib/genit/tags/here_tag.rb +22 -18
- data/lib/genit/utils/news_utils.rb +3 -3
- data/spec/class_news_tag_spec.rb +5 -5
- data/spec/compiler_spec.rb +51 -60
- data/spec/fragment_spec.rb +19 -19
- data/spec/html_document_spec.rb +10 -10
- data/spec/page_compiler_spec.rb +13 -9
- data/spec/pages_finder_spec.rb +11 -11
- data/spec/project_creator_spec.rb +53 -102
- data/spec/test-files/malformed.html +5 -0
- data/spec/xml_document_spec.rb +5 -0
- metadata +6 -9
- data/data/styles/alsa/all.css +0 -130
- data/data/styles/yui/all.css +0 -3
- data/data/styles/yui/base.css +0 -80
- data/data/styles/yui/fonts.css +0 -47
- data/data/styles/yui/reset.css +0 -126
- data/data/templates/xhtml_1.0_strict +0 -5
- data/data/templates/xhtml_1.0_transitional +0 -5
data/lib/genit/server.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'webrick'
|
4
|
+
|
5
|
+
module Genit
|
6
|
+
|
7
|
+
# I use WEBrick to serve the html from the root directory.
|
8
|
+
class Server
|
9
|
+
|
10
|
+
# Public: Constructor.
|
11
|
+
#
|
12
|
+
# wd - The String working directory, where live the project.
|
13
|
+
def initialize wd
|
14
|
+
@server = WEBrick::HTTPServer.new(:Port => 3000, :DocumentRoot => wd)
|
15
|
+
['INT', 'TERM'].each {|signal| trap_this signal }
|
16
|
+
end
|
17
|
+
|
18
|
+
# Start the web server.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
21
|
+
def start
|
22
|
+
puts "Press Ctrl-C to close."
|
23
|
+
@server.start
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def trap_this signal
|
29
|
+
trap(signal) { @server.shutdown }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -14,8 +14,8 @@ module Genit
|
|
14
14
|
def initialize working_dir, template, filename, tag
|
15
15
|
super working_dir, template, filename, tag
|
16
16
|
@file = @tag['file']
|
17
|
-
error "Incomplete #{@tag}"
|
18
|
-
@full_path = File.join(@working_dir,
|
17
|
+
error "Incomplete #{@tag}" unless @tag.key?('file')
|
18
|
+
@full_path = File.join(@working_dir, FRAGMENTS_DIR, @file)
|
19
19
|
error "No such file #{@tag}" unless File.exists?(@full_path)
|
20
20
|
end
|
21
21
|
|
@@ -26,7 +26,8 @@ module Genit
|
|
26
26
|
private
|
27
27
|
|
28
28
|
def build_menu
|
29
|
-
|
29
|
+
file = File.join(@working_dir, TEMPLATES_DIR, "menu.html")
|
30
|
+
menu = XmlDocument.open(file)
|
30
31
|
builder = MenuBuilder.new(menu)
|
31
32
|
@menu = builder.build_for_page(@filename)
|
32
33
|
end
|
@@ -14,36 +14,36 @@ module Genit
|
|
14
14
|
def initialize working_dir, template, filename, tag
|
15
15
|
super working_dir, template, filename, tag
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# Public: Do the replacement.
|
19
19
|
#
|
20
20
|
# Returns the template as a Nokogiri::XML::Document
|
21
21
|
def process
|
22
22
|
replace_tag_into_template! 'genit.news', news_content
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
private
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
26
|
+
|
27
|
+
def news_content
|
28
|
+
news_string = ''
|
29
|
+
news_files.each { |file| news_string += process_the_news(file) }
|
30
|
+
news_string
|
31
|
+
end
|
32
|
+
|
33
|
+
def news_files
|
34
|
+
files = Dir.glob(File.join(@working_dir, NEWS_DIR, '*')).sort.reverse
|
35
|
+
number = @tag['number']
|
36
|
+
return files[0...(number).to_i] if number
|
37
|
+
files
|
38
|
+
end
|
39
|
+
|
40
|
+
def process_the_news file
|
41
|
+
doc_as_string = HtmlDocument.open_as_string(file).to_s
|
42
|
+
wrapper = @tag['wrapper']
|
43
|
+
return "<div class='#{wrapper}'>" + doc_as_string + '</div>' if wrapper
|
44
|
+
doc_as_string
|
45
|
+
end
|
46
|
+
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
end
|
data/lib/genit/tags/here_tag.rb
CHANGED
@@ -16,7 +16,7 @@ module Genit
|
|
16
16
|
def initialize working_dir, template, filename, tag
|
17
17
|
super working_dir, template, filename, tag
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
# Public: Replace a variable in the template. The variable content is found
|
21
21
|
# in the tag in the page.
|
22
22
|
#
|
@@ -25,25 +25,29 @@ module Genit
|
|
25
25
|
replace_tag_into_template! get_css_rule, get_variable_value
|
26
26
|
@template
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
private
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
def get_variable_value
|
37
|
-
doc = HtmlDocument.open_fragment File.join(@working_dir, 'pages', @filename)
|
38
|
-
elem = doc.at_css "genit[what='#{@tag['here']}']"
|
39
|
-
if elem.nil?
|
40
|
-
warning "here without what #{@tag}"
|
41
|
-
""
|
42
|
-
else
|
43
|
-
elem.inner_html
|
30
|
+
|
31
|
+
def get_css_rule
|
32
|
+
var_name = @tag['here']
|
33
|
+
"genit[here='#{var_name}']"
|
44
34
|
end
|
45
|
-
|
46
|
-
|
35
|
+
|
36
|
+
def get_variable_value
|
37
|
+
file = File.join(@working_dir, PAGES_DIR, @filename)
|
38
|
+
doc = HtmlDocument.open_fragment file
|
39
|
+
html_or_nothing_from(doc.at_css("genit[what='#{@tag['here']}']"))
|
40
|
+
end
|
41
|
+
|
42
|
+
def html_or_nothing_from element
|
43
|
+
if element.nil?
|
44
|
+
warning "here without what #{@tag}"
|
45
|
+
""
|
46
|
+
else
|
47
|
+
element.inner_html
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
47
51
|
end
|
48
52
|
|
49
53
|
end
|
data/spec/class_news_tag_spec.rb
CHANGED
@@ -7,11 +7,11 @@ describe ClassNewsTag do
|
|
7
7
|
after :all do
|
8
8
|
clean_test_repository
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def create_sample_project
|
12
|
-
FileUtils.makedirs('spec/project-name/news')
|
13
|
-
File.open('spec/project-name/news/2011-01-01.html', "w") {|out| out.puts '<h1>2011-01-01</h1>' }
|
14
|
-
File.open('spec/project-name/news/2011-02-02.html', "w") {|out| out.puts '<h1>2011-02-02</h1>' }
|
12
|
+
FileUtils.makedirs('spec/project-name/src/news')
|
13
|
+
File.open('spec/project-name/src/news/2011-01-01.html', "w") {|out| out.puts '<h1>2011-01-01</h1>' }
|
14
|
+
File.open('spec/project-name/src/news/2011-02-02.html', "w") {|out| out.puts '<h1>2011-02-02</h1>' }
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should replace all news" do
|
@@ -22,7 +22,7 @@ describe ClassNewsTag do
|
|
22
22
|
doc = cnt.process
|
23
23
|
doc.css('h1').size.should == 2
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "should replace X news" do
|
27
27
|
create_sample_project
|
28
28
|
template = Nokogiri::XML.fragment '<genit class="news" number="1"/>'
|
data/spec/compiler_spec.rb
CHANGED
@@ -5,41 +5,36 @@ require './spec/helper'
|
|
5
5
|
describe Compiler do
|
6
6
|
|
7
7
|
before :each do
|
8
|
-
@project = ProjectCreator.new('spec/project-name',
|
8
|
+
@project = ProjectCreator.new('spec/project-name', false)
|
9
9
|
@project.create
|
10
10
|
@compiler = Compiler.new test_project_path
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
after :each do
|
14
14
|
clean_test_repository
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def write_file name, content
|
18
18
|
File.open(File.join('spec/project-name', name), "w") do |file|
|
19
19
|
file.puts content
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
23
|
-
it "should build an index.html page
|
22
|
+
|
23
|
+
it "should build an index.html page" do
|
24
24
|
@compiler.compile
|
25
|
-
File.exist?('spec/project-name/
|
25
|
+
File.exist?('spec/project-name/index.html').should be_true
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
it "should build two pages" do
|
29
|
-
write_file 'pages/doc.html', '<h1>documentation</h1>'
|
30
|
-
@compiler.compile
|
31
|
-
File.exist?('spec/project-name/www/index.html').should be_true
|
32
|
-
File.exist?('spec/project-name/www/doc.html').should be_true
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should copy the styles/ into www/" do
|
29
|
+
write_file 'src/pages/doc.html', '<h1>documentation</h1>'
|
36
30
|
@compiler.compile
|
37
|
-
File.exist?('spec/project-name/
|
31
|
+
File.exist?('spec/project-name/index.html').should be_true
|
32
|
+
File.exist?('spec/project-name/doc.html').should be_true
|
38
33
|
end
|
39
|
-
|
34
|
+
|
40
35
|
it "should set the menu in index page" do
|
41
36
|
@compiler.compile
|
42
|
-
doc = Nokogiri::HTML(File.open("spec/project-name/
|
37
|
+
doc = Nokogiri::HTML(File.open("spec/project-name/index.html"))
|
43
38
|
doc.at_css("ul#menu a#selected")['href'].should == 'index.html'
|
44
39
|
end
|
45
40
|
|
@@ -50,10 +45,10 @@ describe Compiler do
|
|
50
45
|
end
|
51
46
|
end
|
52
47
|
|
53
|
-
context "with no '
|
48
|
+
context "with no 'config' file" do
|
54
49
|
it "should exit" do
|
55
50
|
$stdout.should_receive(:puts).with(/Missing config file/i)
|
56
|
-
FileUtils.rm 'spec/project-name
|
51
|
+
FileUtils.rm 'spec/project-name/config'
|
57
52
|
lambda{Compiler.new test_project_path}.should raise_error(SystemExit)
|
58
53
|
end
|
59
54
|
end
|
@@ -61,21 +56,21 @@ describe Compiler do
|
|
61
56
|
describe "RSS feed" do
|
62
57
|
it "should build the rss.xml file" do
|
63
58
|
@compiler.compile
|
64
|
-
File.exist?('spec/project-name/
|
59
|
+
File.exist?('spec/project-name/rss.xml').should be_true
|
65
60
|
end
|
66
61
|
end
|
67
62
|
|
68
63
|
describe "Sitemap XML" do
|
69
64
|
it "should build the 'sitemap.xml'" do
|
70
65
|
a_news = %q{<h1>title</h1>}
|
71
|
-
File.open('spec/project-name/news/2011-10-01.html', "w") do |out|
|
66
|
+
File.open('spec/project-name/src/news/2011-10-01.html', "w") do |out|
|
72
67
|
out.puts a_news
|
73
68
|
end
|
74
69
|
@compiler.compile
|
75
|
-
File.exist?('spec/project-name/
|
70
|
+
File.exist?('spec/project-name/sitemap.xml').should be_true
|
76
71
|
end
|
77
72
|
end
|
78
|
-
|
73
|
+
|
79
74
|
context "with bad tag syntax" do
|
80
75
|
context "with unknown class into template" do
|
81
76
|
it "should exit" do
|
@@ -87,7 +82,7 @@ describe Compiler do
|
|
87
82
|
</body>
|
88
83
|
</html>
|
89
84
|
}
|
90
|
-
File.open('spec/project-name/templates/main.html', "w") do |out|
|
85
|
+
File.open('spec/project-name/src/templates/main.html', "w") do |out|
|
91
86
|
out.puts main
|
92
87
|
end
|
93
88
|
|
@@ -97,22 +92,22 @@ describe Compiler do
|
|
97
92
|
end.should raise_error(SystemExit)
|
98
93
|
end
|
99
94
|
end
|
100
|
-
|
95
|
+
|
101
96
|
context "with unknown class into page" do
|
102
97
|
it "should exit" do
|
103
98
|
# replace index.html
|
104
99
|
index = %q{<genit class="foo"/>}
|
105
|
-
File.open('spec/project-name/pages/index.html', "w") do |out|
|
100
|
+
File.open('spec/project-name/src/pages/index.html', "w") do |out|
|
106
101
|
out.puts index
|
107
102
|
end
|
108
|
-
|
103
|
+
|
109
104
|
$stdout.should_receive(:puts).with(/Unknown tag <genit class="foo"/i)
|
110
105
|
lambda do
|
111
106
|
Compiler.new(test_project_path).compile
|
112
107
|
end.should raise_error(SystemExit)
|
113
108
|
end
|
114
109
|
end
|
115
|
-
|
110
|
+
|
116
111
|
context "with incomplete fragment tag into template" do
|
117
112
|
it "should exit" do
|
118
113
|
# replace main.html
|
@@ -123,22 +118,22 @@ describe Compiler do
|
|
123
118
|
</body>
|
124
119
|
</html>
|
125
120
|
}
|
126
|
-
File.open('spec/project-name/templates/main.html', "w") do |out|
|
121
|
+
File.open('spec/project-name/src/templates/main.html', "w") do |out|
|
127
122
|
out.puts main
|
128
123
|
end
|
129
|
-
|
124
|
+
|
130
125
|
$stdout.should_receive(:puts).with(/Incomplete <genit class="fragment"/i)
|
131
126
|
lambda do
|
132
127
|
Compiler.new(test_project_path).compile
|
133
128
|
end.should raise_error(SystemExit)
|
134
129
|
end
|
135
130
|
end
|
136
|
-
|
131
|
+
|
137
132
|
context "with incomplete fragment tag into page" do
|
138
133
|
it "should exit" do
|
139
134
|
# replace index.html
|
140
135
|
index = %q{<genit class="fragment"/>}
|
141
|
-
File.open('spec/project-name/pages/index.html', "w") do |out|
|
136
|
+
File.open('spec/project-name/src/pages/index.html', "w") do |out|
|
142
137
|
out.puts index
|
143
138
|
end
|
144
139
|
|
@@ -148,7 +143,7 @@ describe Compiler do
|
|
148
143
|
end.should raise_error(SystemExit)
|
149
144
|
end
|
150
145
|
end
|
151
|
-
|
146
|
+
|
152
147
|
context "with unknown file in fragment tag into template" do
|
153
148
|
it "should exit" do
|
154
149
|
# replace main.html
|
@@ -159,10 +154,10 @@ describe Compiler do
|
|
159
154
|
</body>
|
160
155
|
</html>
|
161
156
|
}
|
162
|
-
File.open('spec/project-name/templates/main.html', "w") do |out|
|
157
|
+
File.open('spec/project-name/src/templates/main.html', "w") do |out|
|
163
158
|
out.puts main
|
164
159
|
end
|
165
|
-
|
160
|
+
|
166
161
|
rx = /No such file <genit class="fragment" file=/i
|
167
162
|
$stdout.should_receive(:puts).with(rx)
|
168
163
|
lambda do
|
@@ -170,15 +165,15 @@ describe Compiler do
|
|
170
165
|
end.should raise_error(SystemExit)
|
171
166
|
end
|
172
167
|
end
|
173
|
-
|
168
|
+
|
174
169
|
context "with unknown file in fragment tag into page" do
|
175
170
|
it "should exit" do
|
176
171
|
# replace index.html
|
177
172
|
index = %q{<genit class="fragment" file="unknown.html"/>}
|
178
|
-
File.open('spec/project-name/pages/index.html', "w") do |out|
|
173
|
+
File.open('spec/project-name/src/pages/index.html', "w") do |out|
|
179
174
|
out.puts index
|
180
175
|
end
|
181
|
-
|
176
|
+
|
182
177
|
rx = /No such file <genit class="fragment" file=/i
|
183
178
|
$stdout.should_receive(:puts).with(rx)
|
184
179
|
lambda do
|
@@ -186,7 +181,7 @@ describe Compiler do
|
|
186
181
|
end.should raise_error(SystemExit)
|
187
182
|
end
|
188
183
|
end
|
189
|
-
|
184
|
+
|
190
185
|
context "with here tag without what tag" do
|
191
186
|
it "should warn" do
|
192
187
|
# replace main.html
|
@@ -199,19 +194,19 @@ describe Compiler do
|
|
199
194
|
</body>
|
200
195
|
</html>
|
201
196
|
}
|
202
|
-
File.open('spec/project-name/templates/main.html', "w") do |out|
|
197
|
+
File.open('spec/project-name/src/templates/main.html', "w") do |out|
|
203
198
|
out.puts main
|
204
199
|
end
|
205
200
|
$stdout.should_receive(:puts).with(/here without what/i)
|
206
201
|
Compiler.new(test_project_path).compile
|
207
202
|
end
|
208
203
|
end
|
209
|
-
|
204
|
+
|
210
205
|
end
|
211
|
-
|
212
|
-
context "with bad '
|
206
|
+
|
207
|
+
context "with bad 'config' syntax" do
|
213
208
|
it "should exit" do
|
214
|
-
# replace
|
209
|
+
# replace config
|
215
210
|
main =
|
216
211
|
%q{---
|
217
212
|
:address: http://www.example.com
|
@@ -219,38 +214,34 @@ describe Compiler do
|
|
219
214
|
:rss_title: RSS TITLE
|
220
215
|
:rss_description: RSS DESCRIPTION
|
221
216
|
}
|
222
|
-
File.open('spec/project-name
|
223
|
-
|
224
|
-
$stdout.should_receive(:puts).with(/in
|
217
|
+
File.open('spec/project-name/config', "w") {|out| out.puts main }
|
218
|
+
|
219
|
+
$stdout.should_receive(:puts).with(/in config file/i)
|
225
220
|
lambda do
|
226
221
|
Compiler.new(test_project_path).compile
|
227
222
|
end.should raise_error(SystemExit)
|
228
223
|
end
|
229
224
|
end
|
230
|
-
|
225
|
+
|
231
226
|
describe "BUGS" do
|
232
227
|
|
233
228
|
it "should compile to valid HTML5" do
|
234
229
|
@compiler.compile
|
235
|
-
file = File.open("spec/project-name/
|
230
|
+
file = File.open("spec/project-name/index.html", "r")
|
236
231
|
contents = file.read
|
237
|
-
puts "*************"
|
238
|
-
puts contents
|
239
232
|
expected = '<!DOCTYPE html>'
|
240
233
|
contents.start_with?(expected).should be_true
|
241
234
|
end
|
242
|
-
|
235
|
+
|
243
236
|
it "should allow template to include a fragment (Bug#37)" do
|
244
237
|
# add a fragment
|
245
|
-
File.open('spec/project-name/fragments/footer.html', "w") do |out|
|
238
|
+
File.open('spec/project-name/src/fragments/footer.html', "w") do |out|
|
246
239
|
out.puts '<p>footer</p>'
|
247
240
|
end
|
248
241
|
# replace main.html
|
249
242
|
main = %q{
|
250
|
-
|
251
|
-
|
252
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
253
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
243
|
+
<!DOCTYPE html>
|
244
|
+
<html lang="en">
|
254
245
|
<head>
|
255
246
|
<title>Genit - Static web site framework</title>
|
256
247
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
@@ -267,12 +258,12 @@ describe Compiler do
|
|
267
258
|
<genit class="fragment" file="footer.html"/>
|
268
259
|
</body>
|
269
260
|
</html>}
|
270
|
-
File.open('spec/project-name/templates/main.html', "w") do |out|
|
261
|
+
File.open('spec/project-name/src/templates/main.html', "w") do |out|
|
271
262
|
out.puts main
|
272
263
|
end
|
273
264
|
lambda {@compiler.compile}.should_not raise_error
|
274
265
|
end
|
275
|
-
|
266
|
+
|
276
267
|
end
|
277
|
-
|
268
|
+
|
278
269
|
end
|