genit 1.0.1 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/NEWS +12 -28
  2. data/README.markdown +6 -2
  3. data/Rakefile +1 -1
  4. data/TODO +177 -12
  5. data/VERSION +1 -1
  6. data/bin/genit +18 -20
  7. data/data/styles/screen.css +5 -9
  8. data/data/templates/main.html +0 -1
  9. data/lib/genit.rb +9 -4
  10. data/lib/genit/builders/body_link_builder.rb +8 -8
  11. data/lib/genit/builders/builder_base.rb +11 -11
  12. data/lib/genit/builders/head_link_builder.rb +8 -8
  13. data/lib/genit/builders/relativizer.rb +12 -12
  14. data/lib/genit/builders/script_builder.rb +7 -7
  15. data/lib/genit/documents/document_writer.rb +14 -14
  16. data/lib/genit/documents/fragment.rb +23 -22
  17. data/lib/genit/documents/xml_document.rb +5 -1
  18. data/lib/genit/project.rb +1 -0
  19. data/lib/genit/project/compiler.rb +54 -73
  20. data/lib/genit/project/page_compiler.rb +41 -41
  21. data/lib/genit/project/pages_finder.rb +6 -6
  22. data/lib/genit/project/project_creator.rb +116 -111
  23. data/lib/genit/project/root_cleaner.rb +31 -0
  24. data/lib/genit/project/rss_feed.rb +14 -14
  25. data/lib/genit/server.rb +2 -0
  26. data/lib/genit/server/server.rb +33 -0
  27. data/lib/genit/tags/class_fragment_tag.rb +2 -2
  28. data/lib/genit/tags/class_menu_tag.rb +2 -1
  29. data/lib/genit/tags/class_news_tag.rb +24 -24
  30. data/lib/genit/tags/class_pages_tag.rb +1 -1
  31. data/lib/genit/tags/here_tag.rb +22 -18
  32. data/lib/genit/utils/news_utils.rb +3 -3
  33. data/spec/class_news_tag_spec.rb +5 -5
  34. data/spec/compiler_spec.rb +51 -60
  35. data/spec/fragment_spec.rb +19 -19
  36. data/spec/html_document_spec.rb +10 -10
  37. data/spec/page_compiler_spec.rb +13 -9
  38. data/spec/pages_finder_spec.rb +11 -11
  39. data/spec/project_creator_spec.rb +53 -102
  40. data/spec/test-files/malformed.html +5 -0
  41. data/spec/xml_document_spec.rb +5 -0
  42. metadata +6 -9
  43. data/data/styles/alsa/all.css +0 -130
  44. data/data/styles/yui/all.css +0 -3
  45. data/data/styles/yui/base.css +0 -80
  46. data/data/styles/yui/fonts.css +0 -47
  47. data/data/styles/yui/reset.css +0 -126
  48. data/data/templates/xhtml_1.0_strict +0 -5
  49. 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
- def update link
20
- super link, "href"
21
- end
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
- def make_relative nb
41
- nb.times { @path = '../' + @path }
42
- end
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
- def update link
20
- super link, "href"
21
- end
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
- 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
-
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
- def update link
20
- super link, "src"
21
- end
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
- 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, 'www', filename)
36
- end
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}" if @file.nil?
21
- error "No such file #{tag}" unless File.exists?(File.join(@working_dir, 'fragments', @file))
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
- def replace_fragment
37
- builder = Builder.new(@page)
38
- @page = builder.replace(css_rule, content)
39
- end
40
-
41
- def css_rule
42
- "genit.fragment[file='#{@file}']"
43
- end
44
-
45
- def content
46
- full_path = File.join(@working_dir, 'fragments', @file)
47
- HtmlDocument.open_as_string(full_path)
48
- end
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
- Nokogiri::XML(File.open(file))
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.
@@ -4,3 +4,4 @@ require 'genit/project/compiler'
4
4
  require 'genit/project/page_compiler'
5
5
  require 'genit/project/rss_feed'
6
6
  require 'genit/project/pages_finder'
7
+ require 'genit/project/root_cleaner'
@@ -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 '.config', 'Missing config 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
- remove_content_of_www
19
+ RootCleaner.new(@working_dir).clean
22
20
  compile_site
23
21
  end
24
-
22
+
25
23
  private
26
-
27
- def check_missing_file filename, message
28
- unless File.exist?(File.join(@working_dir, filename))
29
- error message
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
- end
32
-
33
- def remove_content_of_www
34
- Dir.foreach(File.join(@working_dir, 'www')) do |file|
35
- next if (file == ".") or (file == "..")
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
- end
41
-
42
- def compile_site
43
- compile_pages
44
- copy_static_content
45
- create_rss_feed
46
- create_sitemap_xml
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
- end
56
-
57
- def compile_page
58
- pc = PageCompiler.new @working_dir, @filename
59
- @page = pc.compile
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
- return unless config_file[:rss]
84
- RssFeed.new(@working_dir, all_news_files, config_file).generate_rss
85
- end
86
-
87
- def create_sitemap_xml
88
- pages = PagesFinder.new(@working_dir).find
89
- config_file = YAML.load_file(File.join(@working_dir, '.config'))
90
- urls = PagesFinder.pagenames2urls(pages, config_file[:address])
91
- sitemap = Sitemap.new(urls).get
92
- FileWriter.write sitemap, File.join(@working_dir, 'www', 'sitemap.xml')
93
- end
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