gettalong-webgen 0.5.5.20081001 → 0.5.5.20081010
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/doc/extensions.page +1 -1
- data/doc/reference_configuration.page +85 -0
- data/doc/tag/tikz.page +158 -0
- data/lib/webgen/common/sitemap.rb +2 -3
- data/lib/webgen/contentprocessor/blocks.rb +0 -2
- data/lib/webgen/contentprocessor/context.rb +0 -3
- data/lib/webgen/contentprocessor/erubis.rb +0 -2
- data/lib/webgen/default_config.rb +8 -1
- data/lib/webgen/node.rb +49 -24
- data/lib/webgen/page.rb +25 -15
- data/lib/webgen/path.rb +20 -10
- data/lib/webgen/sourcehandler/base.rb +36 -14
- data/lib/webgen/sourcehandler/copy.rb +2 -2
- data/lib/webgen/sourcehandler/directory.rb +16 -13
- data/lib/webgen/sourcehandler/feed.rb +3 -6
- data/lib/webgen/sourcehandler/fragment.rb +6 -11
- data/lib/webgen/sourcehandler/memory.rb +41 -0
- data/lib/webgen/sourcehandler/metainfo.rb +21 -21
- data/lib/webgen/sourcehandler/page.rb +8 -12
- data/lib/webgen/sourcehandler/sitemap.rb +0 -2
- data/lib/webgen/sourcehandler/template.rb +0 -4
- data/lib/webgen/sourcehandler/virtual.rb +18 -18
- data/lib/webgen/sourcehandler.rb +83 -70
- data/lib/webgen/tag/breadcrumbtrail.rb +1 -4
- data/lib/webgen/tag/coderay.rb +0 -3
- data/lib/webgen/tag/date.rb +0 -2
- data/lib/webgen/tag/executecommand.rb +1 -2
- data/lib/webgen/tag/includefile.rb +1 -3
- data/lib/webgen/tag/langbar.rb +1 -4
- data/lib/webgen/tag/menu.rb +1 -4
- data/lib/webgen/tag/metainfo.rb +0 -2
- data/lib/webgen/tag/relocatable.rb +2 -3
- data/lib/webgen/tag/sitemap.rb +0 -3
- data/lib/webgen/tag/tikz.rb +117 -0
- data/lib/webgen/tag.rb +1 -0
- data/lib/webgen/tree.rb +9 -5
- data/test/test_common_sitemap.rb +4 -4
- data/test/test_contentprocessor_context.rb +1 -1
- data/test/test_contentprocessor_redcloth.rb +1 -0
- data/test/test_contentprocessor_tags.rb +1 -1
- data/test/test_node.rb +33 -13
- data/test/test_output_filesystem.rb +1 -1
- data/test/test_page.rb +13 -4
- data/test/test_path.rb +37 -5
- data/test/test_source_filesystem.rb +1 -1
- data/test/test_source_stacked.rb +1 -1
- data/test/test_sourcehandler_base.rb +30 -1
- data/test/test_sourcehandler_copy.rb +1 -1
- data/test/test_sourcehandler_directory.rb +16 -1
- data/test/test_sourcehandler_feed.rb +6 -7
- data/test/test_sourcehandler_fragment.rb +1 -1
- data/test/test_sourcehandler_memory.rb +42 -0
- data/test/test_sourcehandler_metainfo.rb +23 -21
- data/test/test_sourcehandler_page.rb +5 -7
- data/test/test_sourcehandler_template.rb +1 -1
- data/test/test_sourcehandler_virtual.rb +2 -2
- data/test/test_tag_base.rb +0 -1
- data/test/test_tag_breadcrumbtrail.rb +4 -4
- data/test/test_tag_includefile.rb +3 -3
- data/test/test_tag_langbar.rb +5 -6
- data/test/test_tag_menu.rb +7 -7
- data/test/test_tag_metainfo.rb +1 -1
- data/test/test_tag_relocatable.rb +1 -1
- data/test/test_tag_tikz.rb +66 -0
- data/test/test_tree.rb +2 -7
- metadata +7 -2
data/lib/webgen/tag/langbar.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'webgen/tag'
|
2
|
-
require 'webgen/websiteaccess'
|
3
|
-
|
4
1
|
module Webgen::Tag
|
5
2
|
|
6
3
|
# Generates a list with all the languages of the page.
|
@@ -41,7 +38,7 @@ module Webgen::Tag
|
|
41
38
|
lang_nodes = all_lang_nodes(node.tree[acn, :acn]) rescue nil
|
42
39
|
if !lang_nodes || lang_nodes.length != clang_nodes.length ||
|
43
40
|
lang_nodes.any? {|n| n.meta_info_changed?}
|
44
|
-
node.dirty
|
41
|
+
node.flag(:dirty)
|
45
42
|
break
|
46
43
|
end
|
47
44
|
end
|
data/lib/webgen/tag/menu.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'webgen/websiteaccess'
|
2
|
-
require 'webgen/tag'
|
3
|
-
|
4
1
|
module Webgen::Tag
|
5
2
|
|
6
3
|
# Generates a menu that can be configured extensively.
|
@@ -90,7 +87,7 @@ module Webgen::Tag
|
|
90
87
|
(tree_list && tree_list.flatten.any? do |alcn|
|
91
88
|
(n = node.tree[alcn]) && (r = n.routing_node(cn.lang)) && r != node && r.meta_info_changed?
|
92
89
|
end)
|
93
|
-
node.dirty
|
90
|
+
node.flag(:dirty)
|
94
91
|
break
|
95
92
|
end
|
96
93
|
end
|
data/lib/webgen/tag/metainfo.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'webgen/tag'
|
2
1
|
require 'uri'
|
3
2
|
|
4
3
|
module Webgen::Tag
|
@@ -27,11 +26,11 @@ module Webgen::Tag
|
|
27
26
|
end
|
28
27
|
if result.empty?
|
29
28
|
log(:error) { "Could not resolve path '#{uri_string}' in <#{context.ref_node.absolute_lcn}>" }
|
30
|
-
context.dest_node.dirty
|
29
|
+
context.dest_node.flag(:dirty)
|
31
30
|
end
|
32
31
|
rescue URI::InvalidURIError => e
|
33
32
|
log(:error) { "Error while parsing path for tag relocatable in <#{context.ref_node.absolute_lcn}>: #{e.message}" }
|
34
|
-
context.dest_node.dirty
|
33
|
+
context.dest_node.flag(:dirty)
|
35
34
|
end
|
36
35
|
end
|
37
36
|
result
|
data/lib/webgen/tag/sitemap.rb
CHANGED
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
module Webgen::Tag
|
6
|
+
|
7
|
+
# This tag allows the creation and inclusion of complex graphics using the PGF/TikZ library of
|
8
|
+
# LaTeX. You will need a current LaTeX distribution and the +convert+ utility from ImageMagick.
|
9
|
+
class TikZ
|
10
|
+
|
11
|
+
include Webgen::Tag::Base
|
12
|
+
include Webgen::WebsiteAccess
|
13
|
+
|
14
|
+
LATEX_TEMPLATE = <<EOF
|
15
|
+
\\nonstopmode \\documentclass{article} \\usepackage{tikz} \\pagestyle{empty}
|
16
|
+
<% if param('tag.tikz.libraries') %>
|
17
|
+
\\usetikzlibrary{<%= param('tag.tikz.libraries').join(',') %>}
|
18
|
+
<% end %>
|
19
|
+
\\begin{document}
|
20
|
+
<% if param('tag.tikz.opts') %>
|
21
|
+
\\begin{tikzpicture}[<%= param('tag.tikz.opts') %>]
|
22
|
+
<% else %>
|
23
|
+
\\begin{tikzpicture}
|
24
|
+
<% end %>
|
25
|
+
<%= body %>
|
26
|
+
\\end{tikzpicture}
|
27
|
+
\\end{document}
|
28
|
+
EOF
|
29
|
+
|
30
|
+
# Create a graphic from the commands in the body of the tag.
|
31
|
+
def call(tag, body, context)
|
32
|
+
path = param('tag.tikz.path')
|
33
|
+
path = Pathname.new(path =~ /^\// ? path : File.join(context.ref_node.parent.absolute_lcn, path)).cleanpath.to_s
|
34
|
+
|
35
|
+
mem_handler = website.cache.instance('Webgen::SourceHandler::Memory')
|
36
|
+
src_path = context.ref_node.node_info[:src]
|
37
|
+
parent = website.blackboard.invoke(:create_directories, context.ref_node.tree.root, File.dirname(path), src_path)
|
38
|
+
params = @params
|
39
|
+
|
40
|
+
node = website.blackboard.invoke(:create_nodes, parent.tree, parent.absolute_lcn,
|
41
|
+
Webgen::Path.new(path, src_path), mem_handler) do |node_parent, node_path|
|
42
|
+
mem_handler.create_node(node_parent, node_path, context.ref_node.absolute_lcn) do |pic_node|
|
43
|
+
set_params(params)
|
44
|
+
document = ERB.new(LATEX_TEMPLATE).result(binding)
|
45
|
+
pic_path = compile(document, File.extname(path), context)
|
46
|
+
set_params(nil)
|
47
|
+
if pic_path
|
48
|
+
io = Webgen::Path::SourceIO.new { File.open(pic_path, 'rb') }
|
49
|
+
else
|
50
|
+
pic_node.flag(:dirty)
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end.first
|
55
|
+
attrs = param('tag.tikz.img_attr').collect {|name,value| "#{name.to_s}=\"#{value}\"" }.sort.unshift('').join(' ')
|
56
|
+
"<img src=\"#{context.dest_node.route_to(node)}\"#{attrs} />"
|
57
|
+
end
|
58
|
+
|
59
|
+
#######
|
60
|
+
private
|
61
|
+
#######
|
62
|
+
|
63
|
+
# Compile the LaTeX +document+ and convert the resulting PDF to the correct output image format
|
64
|
+
# specified by +ext+ (the extension needs to include the dot).
|
65
|
+
def compile(document, ext, context)
|
66
|
+
file = Tempfile.new('webgen-tikz')
|
67
|
+
file.write(document)
|
68
|
+
file.close
|
69
|
+
|
70
|
+
FileUtils.mv(file.path, file.path + '.tex')
|
71
|
+
cmd_prefix = "cd #{File.dirname(file.path)}; "
|
72
|
+
output = `#{cmd_prefix} pdflatex --shell-escape -interaction=batchmode #{File.basename(file.path)}.tex`
|
73
|
+
if $?.exitstatus != 0
|
74
|
+
errors = output.scan(/^!(.*\n.*)/).join("\n")
|
75
|
+
log(:error) { "There was an error creating a TikZ picture in <#{context.ref_node.absolute_lcn}>: #{errors}"}
|
76
|
+
context.dest_node.flag(:dirty)
|
77
|
+
nil
|
78
|
+
else
|
79
|
+
cmd = cmd_prefix + "pdfcrop #{File.basename(file.path)}.pdf #{File.basename(file.path)}.pdf; "
|
80
|
+
return unless run_command(cmd, context)
|
81
|
+
|
82
|
+
render_res, output_res = param('tag.tikz.resolution').split(' ')
|
83
|
+
if param('tag.tikz.transparent') && ext =~ /\.png/i
|
84
|
+
cmd = cmd_prefix +
|
85
|
+
"gs -dSAFER -dBATCH -dNOPAUSE -r#{render_res} -sDEVICE=pngalpha -dGraphicsAlphaBits=4 -dTextAlphaBits=4 " +
|
86
|
+
"-sOutputFile=#{File.basename(file.path)}#{ext} #{File.basename(file.path)}.pdf"
|
87
|
+
else
|
88
|
+
cmd = cmd_prefix + "convert -density #{render_res} #{File.basename(file.path)}.pdf #{File.basename(file.path)}#{ext}"
|
89
|
+
end
|
90
|
+
return unless run_command(cmd, context)
|
91
|
+
|
92
|
+
if render_res != output_res
|
93
|
+
cmd = cmd_prefix + "identify #{File.basename(file.path)}#{ext}"
|
94
|
+
return unless (output = run_command(cmd, context))
|
95
|
+
width, height = output.scan(/\s\d+x\d+\s/).first.strip.split('x').collect {|s| s.to_f * output_res.to_f / render_res.to_f }
|
96
|
+
cmd = cmd_prefix + "convert -resize #{width}x#{height} #{File.basename(file.path)}#{ext} #{File.basename(file.path)}#{ext}"
|
97
|
+
return unless run_command(cmd, context)
|
98
|
+
end
|
99
|
+
file.path + ext
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Runs the command +cmd+ and returns it's output if successful or +nil+ otherwise.
|
104
|
+
def run_command(cmd, context)
|
105
|
+
output = `#{cmd}`
|
106
|
+
if $?.exitstatus != 0
|
107
|
+
log(:error) { "There was an error running a command for a TikZ picture in <#{context.ref_node.absolute_lcn}>: #{output}"}
|
108
|
+
context.dest_node.flag(:dirty)
|
109
|
+
nil
|
110
|
+
else
|
111
|
+
output
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
data/lib/webgen/tag.rb
CHANGED
data/lib/webgen/tree.rb
CHANGED
@@ -51,6 +51,11 @@ module Webgen
|
|
51
51
|
@node_access[:alcn][node.absolute_lcn] = node
|
52
52
|
end
|
53
53
|
(@node_access[:acn][node.absolute_cn] ||= []) << node
|
54
|
+
register_path(node)
|
55
|
+
end
|
56
|
+
|
57
|
+
# A utility method called by Node#reinit. This method should not be used directly!
|
58
|
+
def register_path(node)
|
54
59
|
if @node_access[:path].has_key?(node.path)
|
55
60
|
raise "Can't have two nodes with same output path: #{node.path}" unless node['no_output']
|
56
61
|
else
|
@@ -58,13 +63,12 @@ module Webgen
|
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
61
|
-
# Delete the node identified by +node_or_alcn+ and all of its children from the
|
62
|
-
|
63
|
-
def delete_node(node_or_alcn, delete_dir = false)
|
66
|
+
# Delete the node identified by +node_or_alcn+ and all of its children from the tree.
|
67
|
+
def delete_node(node_or_alcn)
|
64
68
|
n = node_or_alcn.kind_of?(Node) ? node_or_alcn : @node_access[:alcn][node_or_alcn]
|
65
|
-
return if n.nil? || n == @dummy_root
|
69
|
+
return if n.nil? || n == @dummy_root
|
66
70
|
|
67
|
-
n.children.dup.each {|child| delete_node(child
|
71
|
+
n.children.dup.each {|child| delete_node(child)}
|
68
72
|
|
69
73
|
website.blackboard.dispatch_msg(:before_node_deleted, n)
|
70
74
|
n.parent.children.delete(n)
|
data/test/test_common_sitemap.rb
CHANGED
@@ -44,13 +44,13 @@ class TestCommonSitemap < Test::Unit::TestCase
|
|
44
44
|
do_assert(@nodes[:file1_de], 'de', false, true, ['page'],
|
45
45
|
[:dir1, :file11_en, :file1_de, :index_en])
|
46
46
|
|
47
|
-
@nodes[:file11_en].dirty
|
47
|
+
@nodes[:file11_en].unflag(:dirty)
|
48
48
|
@website.blackboard.dispatch_msg(:node_changed?, @nodes[:file11_en])
|
49
|
-
assert(!@nodes[:file11_en].dirty)
|
49
|
+
assert(!@nodes[:file11_en].flagged(:dirty))
|
50
50
|
|
51
|
-
@nodes[:file11_en].dirty_meta_info
|
51
|
+
@nodes[:file11_en].flag(:dirty_meta_info)
|
52
52
|
@website.blackboard.dispatch_msg(:node_changed?, @nodes[:file11_en])
|
53
|
-
assert(@nodes[:file11_en].dirty)
|
53
|
+
assert(@nodes[:file11_en].flagged(:dirty))
|
54
54
|
end
|
55
55
|
|
56
56
|
end
|
data/test/test_node.rb
CHANGED
@@ -31,7 +31,7 @@ class TestNode < Test::Unit::TestCase
|
|
31
31
|
}
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def test_initialize_and_reinit
|
35
35
|
check_proc = proc do |node, parent, path, cn, lcn, alcn, lang, mi|
|
36
36
|
assert_equal(parent, node.parent)
|
37
37
|
assert_equal(path, node.path)
|
@@ -39,8 +39,8 @@ class TestNode < Test::Unit::TestCase
|
|
39
39
|
assert_equal(lcn, node.lcn)
|
40
40
|
assert_equal(alcn, node.absolute_lcn)
|
41
41
|
assert_equal(lang, node.lang)
|
42
|
-
assert(node.dirty)
|
43
|
-
assert(node.created)
|
42
|
+
assert(node.flagged(:dirty))
|
43
|
+
assert(node.flagged(:created))
|
44
44
|
assert_equal(mi, node.meta_info)
|
45
45
|
assert_equal({:used_nodes => Set.new, :used_meta_info_nodes => Set.new}, node.node_info)
|
46
46
|
mi.each {|k,v| assert_equal(v, node[k])}
|
@@ -55,9 +55,13 @@ class TestNode < Test::Unit::TestCase
|
|
55
55
|
|
56
56
|
['http://webgen.rubyforge.org', 'c:\\test'].each_with_index do |abspath, index|
|
57
57
|
cn = 'test' + index.to_s + '.html'
|
58
|
-
|
59
|
-
check_proc.call(
|
58
|
+
c = Webgen::Node.new(node, abspath, cn)
|
59
|
+
check_proc.call(c, node, abspath, cn, cn, '/test/' + cn, nil, {})
|
60
60
|
end
|
61
|
+
|
62
|
+
child.reinit('somename.en.html', {'lang' => 'de', 'title' => 'test'})
|
63
|
+
check_proc.call(child, node, 'somename.en.html', 'somename.page', 'somename.de.page',
|
64
|
+
'/test/somename.de.page', 'de', {'title' => 'test'})
|
61
65
|
end
|
62
66
|
|
63
67
|
def test_type_checkers
|
@@ -77,6 +81,22 @@ class TestNode < Test::Unit::TestCase
|
|
77
81
|
assert_equal(:value, node[:other])
|
78
82
|
end
|
79
83
|
|
84
|
+
def test_flags
|
85
|
+
node = Webgen::Node.new(@tree.dummy_root, 'test/', 'test', {'lang' => 'de', :test => :value})
|
86
|
+
assert(node.flagged(:created))
|
87
|
+
assert(node.flagged(:dirty))
|
88
|
+
node.unflag(:dirty)
|
89
|
+
assert(!node.flagged(:dirty))
|
90
|
+
node.flag(:a, :b, :c)
|
91
|
+
assert(node.flagged(:a))
|
92
|
+
assert(node.flagged(:b))
|
93
|
+
assert(node.flagged(:c))
|
94
|
+
node.unflag(:a, :b, :c)
|
95
|
+
assert(!node.flagged(:a))
|
96
|
+
assert(!node.flagged(:b))
|
97
|
+
assert(!node.flagged(:c))
|
98
|
+
end
|
99
|
+
|
80
100
|
def test_in_lang
|
81
101
|
nodes = create_default_nodes
|
82
102
|
|
@@ -143,16 +163,16 @@ class TestNode < Test::Unit::TestCase
|
|
143
163
|
|
144
164
|
def test_changed
|
145
165
|
node = Webgen::Node.new(@tree.dummy_root, 'test/', 'test', {'lang' => 'de', :test => :value})
|
146
|
-
node.dirty
|
166
|
+
node.unflag(:dirty, :created)
|
147
167
|
|
148
168
|
calls = 0
|
149
|
-
@website.blackboard.add_listener(:node_changed?) {|n| assert(node, n); node.dirty
|
169
|
+
@website.blackboard.add_listener(:node_changed?) {|n| assert(node, n); node.flag(:dirty); calls += 1}
|
150
170
|
node.changed?
|
151
171
|
assert_equal(1, calls)
|
152
172
|
node.changed?
|
153
173
|
assert_equal(1, calls)
|
154
174
|
|
155
|
-
node.dirty
|
175
|
+
node.unflag(:dirty)
|
156
176
|
node.node_info[:used_nodes] << node.absolute_lcn
|
157
177
|
node.node_info[:used_nodes] << 'unknown alcn'
|
158
178
|
node.node_info[:used_nodes] << @tree.dummy_root.absolute_lcn
|
@@ -161,8 +181,8 @@ class TestNode < Test::Unit::TestCase
|
|
161
181
|
|
162
182
|
# Test circular depdendence
|
163
183
|
other_node = Webgen::Node.new(@tree.dummy_root, '/other', 'test.l', {'lang' => 'de', :test => :value})
|
164
|
-
other_node.dirty
|
165
|
-
node.dirty
|
184
|
+
other_node.flag(:dirty, :created)
|
185
|
+
node.flag(:dirty)
|
166
186
|
other_node.node_info[:used_nodes] = [node.absolute_lcn]
|
167
187
|
node.node_info[:used_nodes] = [other_node.absolute_lcn]
|
168
188
|
node.changed?
|
@@ -170,16 +190,16 @@ class TestNode < Test::Unit::TestCase
|
|
170
190
|
|
171
191
|
def test_meta_info_changed
|
172
192
|
node = Webgen::Node.new(@tree.dummy_root, '/', '/')
|
173
|
-
node.dirty
|
193
|
+
node.unflag(:dirty, :created)
|
174
194
|
|
175
195
|
calls = 0
|
176
|
-
@website.blackboard.add_listener(:node_meta_info_changed?) {|n| assert(node, n); node.dirty_meta_info
|
196
|
+
@website.blackboard.add_listener(:node_meta_info_changed?) {|n| assert(node, n); node.flag(:dirty_meta_info); calls += 1}
|
177
197
|
assert(node.meta_info_changed?)
|
178
198
|
assert_equal(1, calls)
|
179
199
|
assert(node.meta_info_changed?)
|
180
200
|
assert_equal(1, calls)
|
181
201
|
|
182
|
-
node.dirty_meta_info
|
202
|
+
node.unflag(:dirty_meta_info)
|
183
203
|
node.node_info[:used_meta_info_nodes] << node.absolute_lcn
|
184
204
|
node.node_info[:used_meta_info_nodes] << 'unknown alcn'
|
185
205
|
node.node_info[:used_meta_info_nodes] << @tree.dummy_root.absolute_lcn
|
data/test/test_page.rb
CHANGED
@@ -118,7 +118,7 @@ class TestPage < Test::Unit::TestCase
|
|
118
118
|
content: "content\\n----------- some block start???\\nthings"
|
119
119
|
EOF
|
120
120
|
|
121
|
-
|
121
|
+
INVALID_MI=<<EOF
|
122
122
|
# invalid meta info: none specified
|
123
123
|
- "---\\n---"
|
124
124
|
|
@@ -136,7 +136,9 @@ EOF
|
|
136
136
|
: * [ }
|
137
137
|
---
|
138
138
|
asdf kadsfakl
|
139
|
+
EOF
|
139
140
|
|
141
|
+
INVALID_BLOCKS=<<EOF
|
140
142
|
# two blocks with same name
|
141
143
|
- |
|
142
144
|
aasdf
|
@@ -155,16 +157,23 @@ EOF
|
|
155
157
|
EOF
|
156
158
|
|
157
159
|
def test_invalid_pagefiles
|
158
|
-
testdata = YAML::load(
|
160
|
+
testdata = YAML::load(INVALID_MI)
|
161
|
+
testdata.each_with_index do |data, index|
|
162
|
+
assert_raise(Webgen::WebgenPageFormatError, "test mi item #{index}") { Webgen::Page.from_data(data) }
|
163
|
+
assert_raise(Webgen::WebgenPageFormatError, "test mi item #{index}") { Webgen::Page.meta_info_from_data(data) }
|
164
|
+
end
|
165
|
+
testdata = YAML::load(INVALID_BLOCKS)
|
159
166
|
testdata.each_with_index do |data, index|
|
160
|
-
assert_raise(Webgen::WebgenPageFormatError, "test item #{index}") { Webgen::Page.from_data(data) }
|
167
|
+
assert_raise(Webgen::WebgenPageFormatError, "test blocks item #{index}") { Webgen::Page.from_data(data) }
|
161
168
|
end
|
162
169
|
end
|
163
170
|
|
164
171
|
def test_valid_pagefiles
|
165
172
|
YAML::load(VALID).each_with_index do |data, oindex|
|
173
|
+
mi = Webgen::Page.meta_info_from_data(data['in'])
|
174
|
+
assert_equal(data['meta_info'], mi, "test item #{oindex} - meta info directly")
|
166
175
|
d = Webgen::Page.from_data(data['in'])
|
167
|
-
assert_equal(data['meta_info'], d.meta_info, "test item #{oindex} - meta info")
|
176
|
+
assert_equal(data['meta_info'], d.meta_info, "test item #{oindex} - meta info all")
|
168
177
|
assert_equal(data['blocks'].length*2, d.blocks.length)
|
169
178
|
data['blocks'].each_with_index do |b, index|
|
170
179
|
index += 1
|
data/test/test_path.rb
CHANGED
@@ -7,6 +7,7 @@ class TestPath < Test::Unit::TestCase
|
|
7
7
|
def test_initialize
|
8
8
|
check_proc = proc do |o, path, dir, bn, lang, ext, cn, oi, title|
|
9
9
|
assert_equal(path, o.path)
|
10
|
+
assert_equal(path, o.source_path)
|
10
11
|
assert_equal(dir, o.directory)
|
11
12
|
assert_equal(bn, o.cnbase)
|
12
13
|
assert_equal(lang, o.meta_info['lang'])
|
@@ -38,17 +39,23 @@ class TestPath < Test::Unit::TestCase
|
|
38
39
|
'/', '/', '/', nil, '', '/', nil, '/')
|
39
40
|
check_proc.call(Webgen::Path.new('/dir/'),
|
40
41
|
'/dir/', '/', 'dir', nil, '', 'dir', nil, 'Dir')
|
42
|
+
|
43
|
+
path = Webgen::Path.new('/test/', '/other.path')
|
44
|
+
assert_equal('/other.path', path.source_path)
|
45
|
+
assert_equal('/test/', path.path)
|
41
46
|
end
|
42
47
|
|
43
48
|
def test_mount_at
|
44
49
|
p = Webgen::Path.new('test.de.page')
|
45
50
|
p = p.mount_at('/somedir')
|
46
51
|
assert_equal('/somedir/test.de.page', p.path)
|
52
|
+
assert_equal('/somedir/test.de.page', p.source_path)
|
47
53
|
assert_equal('/somedir/', p.directory)
|
48
54
|
|
49
55
|
p = Webgen::Path.new('/')
|
50
56
|
p = p.mount_at('/somedir')
|
51
57
|
assert_equal('/somedir/', p.path)
|
58
|
+
assert_equal('/somedir/', p.source_path)
|
52
59
|
assert_equal('/', p.directory)
|
53
60
|
assert_equal('somedir', p.cn)
|
54
61
|
assert_equal('Somedir', p.meta_info['title'])
|
@@ -56,6 +63,7 @@ class TestPath < Test::Unit::TestCase
|
|
56
63
|
p = Webgen::Path.new('/source/test.rb')
|
57
64
|
p = p.mount_at('/', '/source/')
|
58
65
|
assert_equal('/test.rb', p.path)
|
66
|
+
assert_equal('/test.rb', p.source_path)
|
59
67
|
assert_equal('/', p.directory)
|
60
68
|
assert_equal('test.rb', p.cn)
|
61
69
|
assert_equal('Test', p.meta_info['title'])
|
@@ -63,9 +71,18 @@ class TestPath < Test::Unit::TestCase
|
|
63
71
|
p = Webgen::Path.new('/source/')
|
64
72
|
p = p.mount_at('/', '/source')
|
65
73
|
assert_equal('/', p.path)
|
74
|
+
assert_equal('/', p.source_path)
|
66
75
|
assert_equal('/', p.directory)
|
67
76
|
assert_equal('/', p.cn)
|
68
77
|
assert_equal('/', p.meta_info['title'])
|
78
|
+
|
79
|
+
p = Webgen::Path.new('/test.rb', '/other.rb')
|
80
|
+
p = p.mount_at('/source/')
|
81
|
+
assert_equal('/source/test.rb', p.path)
|
82
|
+
assert_equal('/other.rb', p.source_path)
|
83
|
+
assert_equal('/source/', p.directory)
|
84
|
+
assert_equal('test.rb', p.cn)
|
85
|
+
assert_equal('Test', p.meta_info['title'])
|
69
86
|
end
|
70
87
|
|
71
88
|
def test_dup
|
@@ -110,11 +127,26 @@ class TestPath < Test::Unit::TestCase
|
|
110
127
|
end
|
111
128
|
|
112
129
|
def test_matching
|
113
|
-
path =
|
114
|
-
assert(path
|
115
|
-
assert(path
|
116
|
-
assert(path
|
117
|
-
assert(path
|
130
|
+
path = '/dir/to/file.de.page'
|
131
|
+
assert(Webgen::Path.match(path, '**/*'))
|
132
|
+
assert(Webgen::Path.match(path, '**/file.de.PAGE'))
|
133
|
+
assert(Webgen::Path.match(path, '/dir/*/file.*.page'))
|
134
|
+
assert(!Webgen::Path.match(path, '**/*.test'))
|
135
|
+
|
136
|
+
path = '/dir/'
|
137
|
+
assert(Webgen::Path.match(path, '/dir/'))
|
138
|
+
assert(Webgen::Path.match(path, '/dir'))
|
139
|
+
|
140
|
+
path = '/dir'
|
141
|
+
assert(Webgen::Path.match(path, '/dir/'))
|
142
|
+
assert(Webgen::Path.match(path, '/dir'))
|
143
|
+
|
144
|
+
path = '/'
|
145
|
+
assert(Webgen::Path.match(path, '/'))
|
146
|
+
assert(!Webgen::Path.match(path, ''))
|
147
|
+
|
148
|
+
path = ''
|
149
|
+
assert(!Webgen::Path.match(path, '/'))
|
118
150
|
end
|
119
151
|
|
120
152
|
def test_introspection
|
data/test/test_source_stacked.rb
CHANGED
@@ -3,11 +3,13 @@ require 'helper'
|
|
3
3
|
require 'webgen/tree'
|
4
4
|
require 'webgen/node'
|
5
5
|
require 'webgen/path'
|
6
|
-
require 'webgen/sourcehandler
|
6
|
+
require 'webgen/sourcehandler'
|
7
7
|
require 'time'
|
8
8
|
|
9
9
|
class TestSourceHandlerBase < Test::Unit::TestCase
|
10
10
|
|
11
|
+
class TestSH; include Webgen::SourceHandler::Base; end
|
12
|
+
|
11
13
|
include Test::WebsiteHelper
|
12
14
|
|
13
15
|
def setup
|
@@ -16,6 +18,33 @@ class TestSourceHandlerBase < Test::Unit::TestCase
|
|
16
18
|
@obj.extend(Webgen::SourceHandler::Base)
|
17
19
|
end
|
18
20
|
|
21
|
+
def test_create_node
|
22
|
+
tree = Webgen::Tree.new
|
23
|
+
path = path_with_meta_info('/path.html')
|
24
|
+
count = 0
|
25
|
+
|
26
|
+
path.instance_eval { @source_path = '/path'}
|
27
|
+
node = @obj.create_node(tree.dummy_root, path) {|n| count +=1 }
|
28
|
+
assert_equal('/path', node.node_info[:src])
|
29
|
+
assert_equal('Object', node.node_info[:processor])
|
30
|
+
assert_kind_of(Time, node['modified_at'])
|
31
|
+
assert_equal(1, count)
|
32
|
+
|
33
|
+
other_node = @obj.create_node(tree.dummy_root, path) {|n| count +=1 }
|
34
|
+
assert_equal(node, other_node)
|
35
|
+
assert_equal(1, count)
|
36
|
+
|
37
|
+
node.flag(:reinit)
|
38
|
+
other_node = @obj.create_node(tree.dummy_root, path) {|n| count +=1 }
|
39
|
+
assert_equal(node, other_node)
|
40
|
+
assert_equal(2, count)
|
41
|
+
|
42
|
+
path.instance_eval { @source_path = '/other' }
|
43
|
+
other_node = @obj.create_node(tree.dummy_root, path) {|n| count +=1 }
|
44
|
+
assert_equal(node, other_node)
|
45
|
+
assert_equal(2, count)
|
46
|
+
end
|
47
|
+
|
19
48
|
def test_node_exists
|
20
49
|
@tree = Webgen::Tree.new
|
21
50
|
node = Webgen::Node.new(@tree.dummy_root, 'test/', 'test', {'lang' => 'de', :test => :value})
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'helper'
|
3
|
-
require 'webgen/sourcehandler
|
3
|
+
require 'webgen/sourcehandler'
|
4
4
|
require 'stringio'
|
5
5
|
|
6
6
|
class TestSourceHandlerDirectory < Test::Unit::TestCase
|
@@ -14,10 +14,25 @@ class TestSourceHandlerDirectory < Test::Unit::TestCase
|
|
14
14
|
assert_not_nil(node)
|
15
15
|
assert_equal(:value, node[:key])
|
16
16
|
|
17
|
+
node.flag(:reinit)
|
17
18
|
assert_equal(node, @obj.create_node(root, path_with_meta_info('/dir/', {:key => :other}) {StringIO.new('')}))
|
18
19
|
assert_equal(:other, node[:key])
|
19
20
|
end
|
20
21
|
|
22
|
+
def test_create_directories
|
23
|
+
@obj = Webgen::SourceHandler::Directory.new
|
24
|
+
shm = Webgen::SourceHandler::Main.new # for using service :create_nodes
|
25
|
+
root = Webgen::Node.new(Webgen::Tree.new.dummy_root, 'test/', 'test')
|
26
|
+
dir = @obj.create_node(root, path_with_meta_info('/dir/'))
|
27
|
+
|
28
|
+
assert_equal(dir, @obj.create_directories(root, '/dir/', path_with_meta_info('/test')))
|
29
|
+
assert_equal(dir, @obj.create_directories(root, 'dir/', path_with_meta_info('/test')))
|
30
|
+
assert_equal(dir, @obj.create_directories(root, 'dir', path_with_meta_info('/test')))
|
31
|
+
|
32
|
+
which = @obj.create_directories(root, 'dir/under/which', path_with_meta_info('/test'))
|
33
|
+
assert_equal(which, @obj.create_directories(root, 'dir/under/which', path_with_meta_info('/test')))
|
34
|
+
end
|
35
|
+
|
21
36
|
def test_content
|
22
37
|
assert_equal('', Webgen::SourceHandler::Directory.new.content(nil))
|
23
38
|
end
|