genit 1.0.1 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -4,7 +4,7 @@ module Genit
|
|
4
4
|
|
5
5
|
# Modify links.
|
6
6
|
class BodyLinkBuilder < Relativizer
|
7
|
-
|
7
|
+
|
8
8
|
# Public: Relativize links.
|
9
9
|
#
|
10
10
|
# page_name - The string filename of the page.
|
@@ -13,13 +13,13 @@ module Genit
|
|
13
13
|
def build_for_page page_name
|
14
14
|
build page_name, @document.css("body a")
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
private
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
|
19
|
+
def update link
|
20
|
+
super link, "href"
|
21
|
+
end
|
22
|
+
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
end
|
@@ -6,7 +6,7 @@ module Genit
|
|
6
6
|
|
7
7
|
# A base class for all builders.
|
8
8
|
class BuilderBase
|
9
|
-
|
9
|
+
|
10
10
|
# Public: Constructor.
|
11
11
|
#
|
12
12
|
# doc - A Nokogiri::XML::Document
|
@@ -14,18 +14,18 @@ module Genit
|
|
14
14
|
raise RuntimeError if doc.nil?
|
15
15
|
@document = doc
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# Define me in child
|
19
19
|
def build_for_page page_name
|
20
20
|
raise NotImplementedError
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def build page_name, elements
|
24
24
|
@page_name = page_name
|
25
25
|
elements.each {|elem| update elem }
|
26
26
|
@document
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def BuilderBase.get_number_of_base_dirs filename
|
30
30
|
return 0 if filename =~ URI::regexp
|
31
31
|
|
@@ -34,13 +34,13 @@ module Genit
|
|
34
34
|
|
35
35
|
return dirs.split('/').size
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
private
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
|
40
|
+
def make_relative nb
|
41
|
+
nb.times { @path = '../' + @path }
|
42
|
+
end
|
43
|
+
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
end
|
@@ -4,7 +4,7 @@ module Genit
|
|
4
4
|
|
5
5
|
# Modify head link tags.
|
6
6
|
class HeadLinkBuilder < Relativizer
|
7
|
-
|
7
|
+
|
8
8
|
# Public: Build the document head link tags of a particular page.
|
9
9
|
#
|
10
10
|
# page_name - The string filename of the page.
|
@@ -13,13 +13,13 @@ module Genit
|
|
13
13
|
def build_for_page page_name
|
14
14
|
build page_name, @document.css("head link")
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
private
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
|
19
|
+
def update link
|
20
|
+
super link, "href"
|
21
|
+
end
|
22
|
+
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
end
|
@@ -7,21 +7,21 @@ module Genit
|
|
7
7
|
# Base class for builder that should relativize
|
8
8
|
# some links in a XHTML document.
|
9
9
|
class Relativizer < BuilderBase
|
10
|
-
|
10
|
+
|
11
11
|
def not_an_internal_link?
|
12
12
|
@path.nil? or @path =~ URI::regexp
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
private
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
|
17
|
+
def update link, field
|
18
|
+
@path = link[field]
|
19
|
+
return if not_an_internal_link?
|
20
|
+
nb = BuilderBase::get_number_of_base_dirs @page_name
|
21
|
+
make_relative nb
|
22
|
+
link[field] = @path
|
23
|
+
end
|
24
|
+
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
end
|
@@ -4,7 +4,7 @@ module Genit
|
|
4
4
|
|
5
5
|
# Modify script tags.
|
6
6
|
class ScriptBuilder < Relativizer
|
7
|
-
|
7
|
+
|
8
8
|
# Public: Relativize the <script src=""> tags of a particular page.
|
9
9
|
#
|
10
10
|
# page_name - The string filename of the page.
|
@@ -13,13 +13,13 @@ module Genit
|
|
13
13
|
def build_for_page page_name
|
14
14
|
build page_name, @document.css("script")
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
private
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
|
19
|
+
def update link
|
20
|
+
super link, "src"
|
21
|
+
end
|
22
22
|
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
end
|
@@ -6,14 +6,14 @@ module Genit
|
|
6
6
|
|
7
7
|
# Write an html or xml document.
|
8
8
|
class DocumentWriter
|
9
|
-
|
9
|
+
|
10
10
|
# Public: Constructor.
|
11
11
|
#
|
12
12
|
# working_dir - the string working directory, where live the project.
|
13
13
|
def initialize working_dir
|
14
14
|
@working_dir = working_dir
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
# Save the document as an xhtml file.
|
18
18
|
#
|
19
19
|
# document - A Nokogiri::HTML or Nokogiri::XML document
|
@@ -23,18 +23,18 @@ module Genit
|
|
23
23
|
remove_remaining_tags
|
24
24
|
FileWriter.write document.to_html, get_full_path(filename.force_html_extension)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
private
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
28
|
+
|
29
|
+
def remove_remaining_tags
|
30
|
+
tags = @document.css 'genit'
|
31
|
+
tags.each {|tag| tag.remove}
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_full_path filename
|
35
|
+
File.join(@working_dir, filename)
|
36
|
+
end
|
37
|
+
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
end
|
@@ -4,49 +4,50 @@ module Genit
|
|
4
4
|
|
5
5
|
# Replace each fragment in a page.
|
6
6
|
class Fragment
|
7
|
-
|
7
|
+
|
8
8
|
# Public: Constructor.
|
9
9
|
#
|
10
10
|
# file - Full String filename of the page.
|
11
11
|
# working_dir - The String working directory, where live the project.
|
12
12
|
def initialize file, working_dir
|
13
|
-
|
14
13
|
@page = HtmlDocument.open_fragment file
|
15
14
|
@working_dir = working_dir
|
16
15
|
HtmlDocument.genit_tags_from(@page).each do |tag|
|
17
16
|
case tag['class']
|
18
17
|
when 'fragment'
|
19
18
|
@file = tag['file']
|
20
|
-
error "Incomplete #{tag}"
|
21
|
-
|
19
|
+
error "Incomplete #{tag}" unless tag.key?('file')
|
20
|
+
unless File.exists?(File.join(@working_dir, FRAGMENTS_DIR, @file))
|
21
|
+
error "No such file #{tag}"
|
22
|
+
end
|
22
23
|
replace_fragment
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
26
|
-
|
27
|
+
|
27
28
|
# Public: Get the page in html format.
|
28
29
|
#
|
29
30
|
# Returns the html code of the page as a String.
|
30
31
|
def to_html
|
31
32
|
@page.to_html
|
32
33
|
end
|
33
|
-
|
34
|
+
|
34
35
|
private
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
36
|
+
|
37
|
+
def replace_fragment
|
38
|
+
builder = Builder.new(@page)
|
39
|
+
@page = builder.replace(css_rule, content)
|
40
|
+
end
|
41
|
+
|
42
|
+
def css_rule
|
43
|
+
"genit.fragment[file='#{@file}']"
|
44
|
+
end
|
45
|
+
|
46
|
+
def content
|
47
|
+
full_path = File.join(@working_dir, FRAGMENTS_DIR, @file)
|
48
|
+
HtmlDocument.open_as_string(full_path)
|
49
|
+
end
|
50
|
+
|
50
51
|
end
|
51
|
-
|
52
|
+
|
52
53
|
end
|
@@ -14,7 +14,11 @@ module Genit
|
|
14
14
|
#
|
15
15
|
# Returns a Nokogiri::XML document.
|
16
16
|
def self.open file
|
17
|
-
|
17
|
+
begin
|
18
|
+
Nokogiri::XML(File.open(file)){|config| config.strict}
|
19
|
+
rescue Nokogiri::XML::SyntaxError => e
|
20
|
+
error "Malformed xhtml in file #{file} : #{e}"
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
24
|
# Public: Open a fragment of xml document.
|
data/lib/genit/project.rb
CHANGED
@@ -1,97 +1,78 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
3
|
module Genit
|
6
4
|
|
7
5
|
# Web site "compiler".
|
8
6
|
class Compiler
|
9
|
-
|
7
|
+
|
10
8
|
# Public: Constructor.
|
11
9
|
#
|
12
10
|
# working_dir - The String working directory, where live the project.
|
13
11
|
def initialize working_dir
|
14
12
|
@working_dir = working_dir
|
15
13
|
check_missing_file '.genit', 'Not a genit project folder'
|
16
|
-
check_missing_file '
|
14
|
+
check_missing_file 'config', 'Missing config file'
|
17
15
|
end
|
18
|
-
|
16
|
+
|
19
17
|
# Public: Compile the web site.
|
20
18
|
def compile
|
21
|
-
|
19
|
+
RootCleaner.new(@working_dir).clean
|
22
20
|
compile_site
|
23
21
|
end
|
24
|
-
|
22
|
+
|
25
23
|
private
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
|
25
|
+
def check_missing_file filename, message
|
26
|
+
unless File.exist?(File.join(@working_dir, filename))
|
27
|
+
error message
|
28
|
+
end
|
30
29
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
filename = File.join(@working_dir, 'www', file)
|
37
|
-
FileUtils.remove_dir(filename) if File.directory?(filename)
|
38
|
-
FileUtils.remove_file(filename) if File.file?(filename)
|
30
|
+
|
31
|
+
def compile_site
|
32
|
+
compile_pages
|
33
|
+
create_rss_feed
|
34
|
+
create_sitemap_xml
|
39
35
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
def compile_pages
|
50
|
-
Dir.glob(File.join(@working_dir, 'pages', '**/*')) do |file|
|
51
|
-
next if File.directory?(file)
|
52
|
-
@filename = file.gsub(File.join(@working_dir, 'pages') + '/', '')
|
53
|
-
compile_page
|
36
|
+
|
37
|
+
def compile_pages
|
38
|
+
Dir.glob(File.join(@working_dir, PAGES_DIR, '**/*')) do |file|
|
39
|
+
next if File.directory?(file)
|
40
|
+
@filename = file.gsub(File.join(@working_dir, PAGES_DIR) + '/', '')
|
41
|
+
compile_page
|
42
|
+
end
|
54
43
|
end
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
save_file_as_xhtml
|
61
|
-
end
|
62
|
-
|
63
|
-
def save_file_as_xhtml
|
64
|
-
doc_writer = DocumentWriter.new @working_dir
|
65
|
-
doc_writer.save_as_xhtml @page, @filename
|
66
|
-
end
|
67
|
-
|
68
|
-
def copy_static_content
|
69
|
-
destination = File.join(@working_dir, 'www')
|
70
|
-
FileUtils.cp_r File.join(@working_dir, 'styles'), destination
|
71
|
-
FileUtils.cp_r File.join(@working_dir, 'public'), destination
|
72
|
-
FileUtils.cp_r File.join(@working_dir, 'scripts'), destination
|
73
|
-
end
|
74
|
-
|
75
|
-
def create_rss_feed
|
76
|
-
all_news_files =
|
77
|
-
Dir.glob(File.join(@working_dir, 'news', '*')).sort.reverse
|
78
|
-
begin
|
79
|
-
config_file = YAML.load_file(File.join(@working_dir, '.config'))
|
80
|
-
rescue ArgumentError => msg
|
81
|
-
error "In .config file: #{msg}"
|
44
|
+
|
45
|
+
def compile_page
|
46
|
+
pc = PageCompiler.new @working_dir, @filename
|
47
|
+
@page = pc.compile
|
48
|
+
save_file_as_xhtml
|
82
49
|
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
50
|
+
|
51
|
+
def save_file_as_xhtml
|
52
|
+
doc_writer = DocumentWriter.new @working_dir
|
53
|
+
doc_writer.save_as_xhtml @page, @filename
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_rss_feed
|
57
|
+
all_news_files =
|
58
|
+
Dir.glob(File.join(@working_dir, NEWS_DIR, '*')).sort.reverse
|
59
|
+
begin
|
60
|
+
config_file = YAML.load_file(File.join(@working_dir, 'config'))
|
61
|
+
rescue Exception => msg
|
62
|
+
error "In config file: #{msg}"
|
63
|
+
end
|
64
|
+
return unless config_file[:rss]
|
65
|
+
RssFeed.new(@working_dir, all_news_files, config_file).generate_rss
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_sitemap_xml
|
69
|
+
pages = PagesFinder.new(@working_dir).find
|
70
|
+
config_file = YAML.load_file(File.join(@working_dir, 'config'))
|
71
|
+
urls = PagesFinder.pagenames2urls(pages, config_file[:address])
|
72
|
+
sitemap = Sitemap.new(urls).get
|
73
|
+
FileWriter.write sitemap, File.join(@working_dir, 'sitemap.xml')
|
74
|
+
end
|
75
|
+
|
95
76
|
end
|
96
|
-
|
77
|
+
|
97
78
|
end
|