genit 0.99 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
data/NEWS CHANGED
@@ -1,6 +1,21 @@
1
+ v1.0 2011-10-02
2
+
3
+ * Genit creates a sitemap.xml
4
+
5
+ * Genit put an error message when:
6
+ - config file not present
7
+ - unknown tag
8
+ - bad or incomplete fragment tag
9
+ - syntax error in .config
10
+
11
+ * Genit put a warning message when a here tag is used without its counterpart
12
+
13
+ * Version is added to the .genit file
14
+
15
+
1
16
  v0.99 2011-09-25
2
17
 
3
- * Genit create an RSS feed for your news articles
18
+ * Genit creates an RSS feed for your news articles
4
19
 
5
20
 
6
21
  v0.9 2011-09-04
data/TODO CHANGED
@@ -1,3 +1,35 @@
1
1
 
2
+ sitemap
3
+ ------------------
4
+ *trouver la liste des pages (et markdown ?))
5
+ *transformer liste page en liste url
6
+ *construire le sitemap
7
+ *tout ensemble
8
+ *la doc
9
+
10
+
11
+ messages erreur
12
+ ----------------
13
+
14
+ *Les deux fichiers cachés doivent être présent à la compil
15
+ *<genit class="foo" /> dans le template fait un RuntimeError. Idem dans une page.
16
+ *<genit class="fragment"/> dans template ou page fait une erreur moche.
17
+ *<genit class="fragment" file="inconnu.html"/> fait une erreur moche.
18
+ *une erreur de syntaxe dans le .config fait une erreur moche.
19
+
20
+ *<genit here="window_title"/> sans contrepartie ne fait rien, il faudrait un warning.
21
+
22
+ si j'écris <h1>news page (en oubliant le tag de fin) Genit ne dis
23
+ rien et ajoute silencieusement le </h1>. Voir si on peut lui faire
24
+ cracher un warning (ou une erreur si pas possible warning).
25
+
26
+ Quand je fais reférence à une url interne inexistante, il serait bon
27
+ d'avoir un warning.
28
+
29
+ dans le dossier page on accepte uniquement .html et .markdown (warning)
30
+
31
+ fichier .genit
32
+ ---------------
33
+ *ajouter la version
2
34
 
3
35
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.99
1
+ 1.0
@@ -6,5 +6,20 @@ require 'genit/utils'
6
6
  require 'genit/builders'
7
7
  require 'genit/tags'
8
8
 
9
+ module Errors
10
+
11
+ def error message
12
+ puts "Error: #{message}"
13
+ exit 1
14
+ end
15
+
16
+ def warning message
17
+ puts "Warning: #{message}"
18
+ end
19
+
20
+ end
21
+
9
22
  module Genit
23
+ include Errors
24
+
10
25
  end
@@ -1,8 +1,10 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require 'genit/builders/builder'
3
3
  require 'genit/builders/builder_base'
4
+ require 'genit/builders/relativizer'
4
5
  require 'genit/builders/menu_builder'
5
6
  require 'genit/builders/head_link_builder'
6
7
  require 'genit/builders/body_link_builder'
7
8
  require 'genit/builders/img_builder'
8
9
  require 'genit/builders/script_builder'
10
+
@@ -1,11 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- require 'uri'
4
-
5
3
  module Genit
6
4
 
7
5
  # Modify links.
8
- class BodyLinkBuilder < BuilderBase
6
+ class BodyLinkBuilder < Relativizer
9
7
 
10
8
  # Public: Relativize links.
11
9
  #
@@ -13,25 +11,13 @@ module Genit
13
11
  #
14
12
  # Returns the modified Nokogiri::XML::Document
15
13
  def build_for_page page_name
16
- build page_name, get_links
14
+ build page_name, @document.css("body a")
17
15
  end
18
16
 
19
17
  private
20
18
 
21
- def get_links
22
- @document.css("body a")
23
- end
24
-
25
19
  def update link
26
- @path = link['href']
27
- return if not_an_internal_link?
28
- nb = BuilderBase::get_number_of_base_dirs @page_name
29
- make_relative nb
30
- link['href'] = @path
31
- end
32
-
33
- def not_an_internal_link?
34
- @path.nil? or @path =~ URI::regexp
20
+ super link, "href"
35
21
  end
36
22
 
37
23
  end
@@ -3,7 +3,7 @@
3
3
  module Genit
4
4
 
5
5
  # Modify head link tags.
6
- class HeadLinkBuilder < BuilderBase
6
+ class HeadLinkBuilder < Relativizer
7
7
 
8
8
  # Public: Build the document head link tags of a particular page.
9
9
  #
@@ -11,25 +11,13 @@ module Genit
11
11
  #
12
12
  # Returns the modified Nokogiri::XML::Document
13
13
  def build_for_page page_name
14
- build page_name, head_links
14
+ build page_name, @document.css("head link")
15
15
  end
16
16
 
17
17
  private
18
18
 
19
- def head_links
20
- @document.css("head link")
21
- end
22
-
23
19
  def update link
24
- @path = link['href']
25
- return if not_an_internal_link?
26
- nb = BuilderBase::get_number_of_base_dirs @page_name
27
- make_relative nb
28
- link['href'] = @path
29
- end
30
-
31
- def not_an_internal_link?
32
- @path.nil? or @path =~ URI::regexp
20
+ super link, "href"
33
21
  end
34
22
 
35
23
  end
@@ -1,11 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- require 'uri'
4
-
5
3
  module Genit
6
4
 
7
5
  # Modify img src.
8
- class ImgBuilder < BuilderBase
6
+ class ImgBuilder < Relativizer
9
7
 
10
8
  # Public: Relativize image source.
11
9
  #
@@ -13,25 +11,13 @@ module Genit
13
11
  #
14
12
  # Returns the modified Nokogiri::XML::Document
15
13
  def build_for_page page_name
16
- build page_name, get_links
14
+ build page_name, @document.css("body img")
17
15
  end
18
16
 
19
17
  private
20
18
 
21
- def get_links
22
- @document.css("body img")
23
- end
24
-
25
19
  def update link
26
- @path = link['src']
27
- return if not_an_internal_link?
28
- nb = BuilderBase::get_number_of_base_dirs @page_name
29
- make_relative nb
30
- link['src'] = @path
31
- end
32
-
33
- def not_an_internal_link?
34
- @path.nil? or @path =~ URI::regexp
20
+ super link, "src"
35
21
  end
36
22
 
37
23
  end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'uri'
4
+
5
+ module Genit
6
+
7
+ # Base class for builder that should relativize
8
+ # some links in a XHTML document.
9
+ class Relativizer < BuilderBase
10
+
11
+ def not_an_internal_link?
12
+ @path.nil? or @path =~ URI::regexp
13
+ end
14
+
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
+
25
+ end
26
+
27
+ end
@@ -3,7 +3,7 @@
3
3
  module Genit
4
4
 
5
5
  # Modify script tags.
6
- class ScriptBuilder < BuilderBase
6
+ class ScriptBuilder < Relativizer
7
7
 
8
8
  # Public: Relativize the <script src=""> tags of a particular page.
9
9
  #
@@ -11,27 +11,15 @@ module Genit
11
11
  #
12
12
  # Returns the modified Nokogiri::XML::Document
13
13
  def build_for_page page_name
14
- build page_name, head_links
14
+ build page_name, @document.css("script")
15
15
  end
16
16
 
17
17
  private
18
18
 
19
- def head_links
20
- @document.css("script")
21
- end
22
-
23
19
  def update link
24
- @path = link['src']
25
- return if not_an_internal_link?
26
- nb = BuilderBase::get_number_of_base_dirs @page_name
27
- make_relative nb
28
- link['src'] = @path
29
- end
30
-
31
- def not_an_internal_link?
32
- @path.nil? or @path =~ URI::regexp
20
+ super link, "src"
33
21
  end
34
-
22
+
35
23
  end
36
24
 
37
25
  end
@@ -3,3 +3,4 @@ require 'genit/documents/html_document'
3
3
  require 'genit/documents/xml_document'
4
4
  require 'genit/documents/fragment'
5
5
  require 'genit/documents/document_writer'
6
+ require 'genit/documents/sitemap'
@@ -10,12 +10,15 @@ module Genit
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
+
13
14
  @page = HtmlDocument.open_fragment file
14
15
  @working_dir = working_dir
15
16
  HtmlDocument.genit_tags_from(@page).each do |tag|
16
17
  case tag['class']
17
18
  when 'fragment'
18
19
  @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
22
  replace_fragment
20
23
  end
21
24
  end
@@ -0,0 +1,44 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Genit
4
+
5
+ # Build an XML sitemap.
6
+ class Sitemap
7
+
8
+ # Public: Constructor.
9
+ #
10
+ # urls - an Array of all the URLs to include in the sitemap.
11
+ def initialize urls
12
+ @builder = Sitemap.builder urls
13
+ end
14
+
15
+ # Public: Get the sitemap
16
+ #
17
+ # Returns the sitemap as a String.
18
+ def get
19
+ @builder.to_xml
20
+ end
21
+
22
+ private
23
+
24
+ def self.builder urls
25
+ Nokogiri::XML::Builder.new { |xml| Sitemap.build_urlset xml, urls }
26
+ end
27
+
28
+ def self.build_urlset xml, urls
29
+ xml.urlset('xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9') do
30
+ Sitemap.build_url_elements xml, urls
31
+ end
32
+ end
33
+
34
+ def self.build_url_elements xml, urls
35
+ urls.each { |elem| Sitemap.build_loc_element xml, elem }
36
+ end
37
+
38
+ def self.build_loc_element xml, elem
39
+ xml.url { xml.loc elem }
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -3,3 +3,4 @@ require 'genit/project/project_creator'
3
3
  require 'genit/project/compiler'
4
4
  require 'genit/project/page_compiler'
5
5
  require 'genit/project/rss_feed'
6
+ require 'genit/project/pages_finder'
@@ -12,22 +12,22 @@ module Genit
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
+ check_missing_file '.genit', 'Not a genit project folder'
16
+ check_missing_file '.config', 'Missing config file'
15
17
  end
16
18
 
17
19
  # Public: Compile the web site.
18
20
  def compile
19
- if genit_project_folder?
20
- remove_content_of_www
21
- compile_site
22
- else
23
- puts 'Not a genit project folder'
24
- end
21
+ remove_content_of_www
22
+ compile_site
25
23
  end
26
24
 
27
25
  private
28
26
 
29
- def genit_project_folder?
30
- File.exist?(File.join(@working_dir, '.genit'))
27
+ def check_missing_file filename, message
28
+ unless File.exist?(File.join(@working_dir, filename))
29
+ error message
30
+ end
31
31
  end
32
32
 
33
33
  def remove_content_of_www
@@ -43,6 +43,7 @@ module Genit
43
43
  compile_pages
44
44
  copy_static_content
45
45
  create_rss_feed
46
+ create_sitemap_xml
46
47
  end
47
48
 
48
49
  def compile_pages
@@ -73,11 +74,23 @@ module Genit
73
74
 
74
75
  def create_rss_feed
75
76
  all_news_files = Dir.glob(File.join(@working_dir, 'news', '*')).sort.reverse
76
- config_file = YAML.load_file(File.join(@working_dir, '.config'))
77
+ begin
78
+ config_file = YAML.load_file(File.join(@working_dir, '.config'))
79
+ rescue ArgumentError => msg
80
+ error "In .config file: #{msg}"
81
+ end
77
82
  return unless config_file[:rss]
78
83
  RssFeed.new(@working_dir, all_news_files, config_file).generate_rss
79
84
  end
80
85
 
86
+ def create_sitemap_xml
87
+ pages = PagesFinder.new(@working_dir).find
88
+ config_file = YAML.load_file(File.join(@working_dir, '.config'))
89
+ urls = PagesFinder.pagenames2urls(pages, config_file[:address])
90
+ sitemap = Sitemap.new(urls).get
91
+ FileWriter.write sitemap, File.join(@working_dir, 'www', 'sitemap.xml')
92
+ end
93
+
81
94
  end
82
95
 
83
96
  end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Genit
4
+
5
+ # I can find the list of all page names, named from
6
+ # the site root.
7
+ class PagesFinder
8
+
9
+ # Public: Constructor.
10
+ #
11
+ # working_dir - The String working directory, where live the project.
12
+ def initialize working_dir
13
+ @working_dir = working_dir
14
+ @pages_folder = File.join(@working_dir, 'pages')
15
+ end
16
+
17
+ # Public: Retrieve the list of all page names.
18
+ #
19
+ # Returns an Array of String.
20
+ def find
21
+ list = Dir.glob(File.join(@pages_folder, '**/*'))
22
+ list.map! { |name| name.gsub(@pages_folder + '/', '')}
23
+ list.map { |name| name.force_html_extension }
24
+ end
25
+
26
+ def self.pagenames2urls array, url_string
27
+ array.map { |name| File.join(url_string, name) }
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -55,13 +55,19 @@ module Genit
55
55
  end
56
56
 
57
57
  def create_the_project_config
58
- FileUtils.touch "#{@project_name}/.genit"
58
+ version = File.read(File.join($GENIT_PATH, 'VERSION')).strip
59
+ write_config version, '.genit'
60
+
59
61
  config_file = { :address => 'http://www.example.com',
60
62
  :rss => true,
61
63
  :rss_title => 'RSS TITLE',
62
64
  :rss_description => 'RSS DESCRIPTION'}.to_yaml
63
- dest = File.join @project_name, '.config'
64
- File.open(dest, "w") {|out| out.puts config_file }
65
+ write_config config_file, '.config'
66
+ end
67
+
68
+ def write_config content, filename
69
+ dest = File.join @project_name, filename
70
+ File.open(dest, "w") {|out| out.puts content }
65
71
  end
66
72
 
67
73
  # Create some subfolders inside the project folder.
@@ -13,15 +13,18 @@ module Genit
13
13
  # tag - The tag to process as a Nokogiri::XML::Element
14
14
  def initialize working_dir, template, filename, tag
15
15
  super working_dir, template, filename, tag
16
+ @file = @tag['file']
17
+ error "Incomplete #{@tag}" if @file.nil?
18
+ @full_path = File.join(@working_dir, 'fragments', @file)
19
+ error "No such file #{@tag}" unless File.exists?(@full_path)
16
20
  end
17
21
 
18
22
  # Public: Do the replacement.
19
23
  #
20
24
  # Returns the template as a Nokogiri::XML::Document
21
25
  def process
22
- file = @tag['file']
23
- fragment = HtmlDocument.build_page_content(File.join(@working_dir, 'fragments', file), @working_dir)
24
- css_rule = "genit.fragment[file='#{file}']"
26
+ fragment = HtmlDocument.build_page_content(@full_path, @working_dir)
27
+ css_rule = "genit.fragment[file='#{@file}']"
25
28
  replace_tag_into_template! css_rule, fragment.to_s
26
29
  end
27
30
 
@@ -3,12 +3,8 @@
3
3
  module Genit
4
4
 
5
5
  # A Genit general tag.
6
- # Currently we have three tags:
7
- # * <genit class="pages"/>
8
- # * <genit class="menu"/>
9
- # * <genit class="fragment" file="foo.html"/>
10
6
  class ClassTag < Tag
11
-
7
+
12
8
  # Public: Constructor.
13
9
  #
14
10
  # working_dir - The String working directory, where live the project.
@@ -29,7 +25,7 @@ module Genit
29
25
  when 'fragment' then ClassFragmentTag.new(@working_dir, @template, @filename, @tag).process
30
26
  when 'news' then ClassNewsTag.new(@working_dir, @template, @filename, @tag).process
31
27
  else
32
- raise RuntimeError
28
+ error "Unknown tag #{@tag}"
33
29
  end
34
30
  end
35
31
 
@@ -34,10 +34,10 @@ module Genit
34
34
  end
35
35
 
36
36
  def get_variable_value
37
- filename = File.join(@working_dir, 'pages', @filename)
38
- doc = HtmlDocument.open_fragment filename
39
- elem = doc.at_css("genit[what='#{@tag['here']}']")
37
+ doc = HtmlDocument.open_fragment File.join(@working_dir, 'pages', @filename)
38
+ elem = doc.at_css "genit[what='#{@tag['here']}']"
40
39
  if elem.nil?
40
+ warning "here without what #{@tag}"
41
41
  ""
42
42
  else
43
43
  elem.inner_html
@@ -7,7 +7,7 @@ describe ClassTag do
7
7
  it "should raise error if class is unknown" do
8
8
  tag = {'class' => 'unknown'}
9
9
  ct = ClassTag.new 'mock', 'mock', 'mock', tag
10
- lambda{ct.process}.should raise_error(RuntimeError)
10
+ lambda{ct.process}.should raise_error(SystemExit)
11
11
  end
12
12
 
13
13
  end
@@ -4,13 +4,13 @@ require './spec/helper'
4
4
 
5
5
  describe Compiler do
6
6
 
7
- before :all do
7
+ before :each do
8
8
  @project = ProjectCreator.new('spec/project-name', 'html_5', false)
9
9
  @project.create
10
- @compiler = Compiler.new File.expand_path('spec/project-name')
10
+ @compiler = Compiler.new test_project_path
11
11
  end
12
12
 
13
- after :all do
13
+ after :each do
14
14
  clean_test_repository
15
15
  end
16
16
 
@@ -33,6 +33,7 @@ describe Compiler do
33
33
  end
34
34
 
35
35
  it "should copy the styles/ into www/" do
36
+ @compiler.compile
36
37
  File.exist?('spec/project-name/www/styles/screen.css').should be_true
37
38
  end
38
39
 
@@ -42,18 +43,162 @@ describe Compiler do
42
43
  doc.at_css("ul#menu a#selected")['href'].should == 'index.html'
43
44
  end
44
45
 
45
- it "should take care of the hidden project file" do
46
- compiler = Compiler.new File.expand_path('.')
47
- $stdout.should_receive(:puts).with("Not a genit project folder")
48
- compiler.compile
46
+ context "with no '.genit' file" do
47
+ it "should exit" do
48
+ $stdout.should_receive(:puts).with(/Not a genit project folder/i)
49
+ lambda{Compiler.new File.expand_path('.')}.should raise_error(SystemExit)
50
+ end
49
51
  end
50
52
 
51
- describe "RSS feed" do
53
+ context "with no '.config' file" do
54
+ it "should exit" do
55
+ $stdout.should_receive(:puts).with(/Missing config file/i)
56
+ FileUtils.rm 'spec/project-name/.config'
57
+ lambda{Compiler.new test_project_path}.should raise_error(SystemExit)
58
+ end
59
+ end
52
60
 
61
+ describe "RSS feed" do
53
62
  it "should build the rss.xml file" do
54
- File.exist?('spec/project-name/www/rss.xml').should be_true
63
+ @compiler.compile
64
+ File.exist?('spec/project-name/www/rss.xml').should be_true
65
+ end
66
+ end
67
+
68
+ describe "Sitemap XML" do
69
+ it "should build the 'sitemap.xml'" do
70
+ a_news = %q{<h1>title</h1>}
71
+ File.open('spec/project-name/news/2011-10-01.html', "w") {|out| out.puts a_news }
72
+ @compiler.compile
73
+ File.exist?('spec/project-name/www/sitemap.xml').should be_true
74
+ end
75
+ end
76
+
77
+ context "with bad tag syntax" do
78
+ context "with unknown class into template" do
79
+ it "should exit" do
80
+ # replace main.html
81
+ main = %q{
82
+ <html>
83
+ <body>
84
+ <genit class="foo"/>
85
+ </body>
86
+ </html>
87
+ }
88
+ File.open('spec/project-name/templates/main.html', "w") {|out| out.puts main }
89
+
90
+ $stdout.should_receive(:puts).with(/Unknown tag <genit class="foo"/i)
91
+ lambda{Compiler.new(test_project_path).compile}.should raise_error(SystemExit)
92
+ end
55
93
  end
56
94
 
95
+ context "with unknown class into page" do
96
+ it "should exit" do
97
+ # replace index.html
98
+ index = %q{<genit class="foo"/>}
99
+ File.open('spec/project-name/pages/index.html', "w") {|out| out.puts index }
100
+
101
+ $stdout.should_receive(:puts).with(/Unknown tag <genit class="foo"/i)
102
+ lambda{Compiler.new(test_project_path).compile}.should raise_error(SystemExit)
103
+ end
104
+ end
105
+
106
+ context "with incomplete fragment tag into template" do
107
+ it "should exit" do
108
+ # replace main.html
109
+ main = %q{
110
+ <html>
111
+ <body>
112
+ <genit class="fragment"/>
113
+ </body>
114
+ </html>
115
+ }
116
+ File.open('spec/project-name/templates/main.html', "w") {|out| out.puts main }
117
+
118
+ $stdout.should_receive(:puts).with(/Incomplete <genit class="fragment"/i)
119
+ lambda{Compiler.new(test_project_path).compile}.should raise_error(SystemExit)
120
+ end
121
+ end
122
+
123
+ context "with incomplete fragment tag into page" do
124
+ it "should exit" do
125
+ # replace index.html
126
+ index = %q{<genit class="fragment"/>}
127
+ File.open('spec/project-name/pages/index.html', "w") {|out| out.puts index }
128
+
129
+ $stdout.should_receive(:puts).with(/Incomplete <genit class="fragment"/i)
130
+ lambda{Compiler.new(test_project_path).compile}.should raise_error(SystemExit)
131
+ end
132
+ end
133
+
134
+ context "with unknown file in fragment tag into template" do
135
+ it "should exit" do
136
+ # replace main.html
137
+ main = %q{
138
+ <html>
139
+ <body>
140
+ <genit class="fragment" file="unknown.html"/>
141
+ </body>
142
+ </html>
143
+ }
144
+ File.open('spec/project-name/templates/main.html', "w") {|out| out.puts main }
145
+
146
+ $stdout.should_receive(:puts).with(/No such file <genit class="fragment" file=/i)
147
+ lambda{Compiler.new(test_project_path).compile}.should raise_error(SystemExit)
148
+ end
149
+ end
150
+
151
+ context "with unknown file in fragment tag into page" do
152
+ it "should exit" do
153
+ # replace index.html
154
+ index = %q{<genit class="fragment" file="unknown.html"/>}
155
+ File.open('spec/project-name/pages/index.html', "w") {|out| out.puts index }
156
+
157
+ $stdout.should_receive(:puts).with(/No such file <genit class="fragment" file=/i)
158
+ lambda{Compiler.new(test_project_path).compile}.should raise_error(SystemExit)
159
+ end
160
+ end
161
+
162
+ context "with here tag without what tag" do
163
+ it "should warn" do
164
+ # replace main.html
165
+ main = %q{
166
+ <html>
167
+ <body>
168
+
169
+ <genit class="pages"/>
170
+ <genit here="foo"/>
171
+ </body>
172
+ </html>
173
+ }
174
+ File.open('spec/project-name/templates/main.html', "w") {|out| out.puts main }
175
+ $stdout.should_receive(:puts).with(/here without what/i)
176
+ #~ lambda{Compiler.new(test_project_path).compile}.should_not raise_error
177
+ Compiler.new(test_project_path).compile
178
+ end
179
+ end
180
+
181
+ context "with what tag without here tag" do
182
+ it "should warn"
183
+ end
184
+
185
+ end
186
+
187
+ context "with bad '.config' syntax" do
188
+ it "should exit" do
189
+ # replace .config
190
+ main =
191
+ %q{---
192
+ :address: http://www.example.com
193
+ :rss: true
194
+ :rss_title: RSS TITLE
195
+ :rss_description: RSS DESCRIPTION
196
+ }
197
+ File.open('spec/project-name/.config', "w") {|out| out.puts main }
198
+
199
+ $stdout.should_receive(:puts).with(/in .config file/i)
200
+ lambda{Compiler.new(test_project_path).compile}.should raise_error(SystemExit)
201
+ end
57
202
  end
58
203
 
59
204
  describe "BUGS" do
@@ -17,3 +17,7 @@ def clean_test_repository
17
17
  FileUtils.remove_file(filename) if File.file?(filename)
18
18
  end
19
19
  end
20
+
21
+ def test_project_path
22
+ File.expand_path('spec/project-name')
23
+ end
@@ -0,0 +1,14 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require './spec/helper'
4
+
5
+ describe NewsUtils do
6
+
7
+ describe "#get_date_from_filename" do
8
+ it "should get the date from a news filename" do
9
+ result = NewsUtils.get_date_from_filename "2011-10-01.html"
10
+ result.should eql "2011-10-01"
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,58 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require './spec/helper'
4
+
5
+ describe PagesFinder do
6
+
7
+ before :each do
8
+ @project = ProjectCreator.new('spec/project-name', 'html_5', false)
9
+ @project.create
10
+ @finder = PagesFinder.new 'spec/project-name'
11
+ end
12
+
13
+ after :each do
14
+ clean_test_repository
15
+ end
16
+
17
+ def write_file name, content
18
+ File.open(File.join('spec/project-name', name), "w") do |file|
19
+ file.puts content
20
+ end
21
+ end
22
+
23
+ it "should retrieve the right number of pages" do
24
+ write_file 'pages/a.html', '<h1>a</h1>'
25
+ write_file 'pages/b.html', '<h1>b</h1>'
26
+ @finder.find.size.should == 3
27
+ end
28
+
29
+ it "should name the pages from the root" do
30
+ write_file 'pages/a.html', '<h1>a</h1>'
31
+ write_file 'pages/b.html', '<h1>b</h1>'
32
+ list = @finder.find
33
+ list.include?("index.html").should be_true
34
+ list.include?("a.html").should be_true
35
+ list.include?("b.html").should be_true
36
+ end
37
+
38
+ it "should take care of markdown files" do
39
+ write_file 'pages/a.markdown', '#a'
40
+ write_file 'pages/b.markdown', '#b'
41
+ list = @finder.find
42
+ list.size.should == 3
43
+ list.include?("index.html").should be_true
44
+ list.include?("a.html").should be_true
45
+ list.include?("b.html").should be_true
46
+ end
47
+
48
+ it "should transform an array of pagenames into an array of URL strings" do
49
+ pagenames = ['a.html', 'b.html', 'c/d.html']
50
+ url = 'http://www.example.com'
51
+ result = PagesFinder.pagenames2urls(pagenames, url)
52
+ result.size.should == 3
53
+ result.include?('http://www.example.com/a.html').should be_true
54
+ result.include?('http://www.example.com/b.html').should be_true
55
+ result.include?('http://www.example.com/c/d.html').should be_true
56
+ end
57
+
58
+ end
@@ -19,6 +19,12 @@ describe ProjectCreator do
19
19
  File.exist?('spec/project-name').should == true
20
20
  end
21
21
 
22
+ it "should create a project folder with version number" do
23
+ a = File.read('VERSION').strip
24
+ b = File.read('spec/project-name/.genit').strip
25
+ b.should eql a
26
+ end
27
+
22
28
  it "should say it if it cannot create a project" do
23
29
  project = ProjectCreator.new('/root/project', 'html_5', false)
24
30
  $stdout.should_receive(:puts).with("Cannot create project...")
@@ -0,0 +1,42 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require './spec/helper'
4
+
5
+ describe Sitemap do
6
+
7
+ before :each do
8
+ @sitemap = Sitemap.new ['a.html', 'b.html', 'c.html']
9
+ end
10
+
11
+ it "should return a string" do
12
+ @sitemap.get.class.should == String
13
+ end
14
+
15
+ it "should have only one <urlset> element" do
16
+ doc = Nokogiri::XML::Document.parse @sitemap.get
17
+ doc.css("urlset").size.should == 1
18
+ end
19
+
20
+ it "should have the right <urlset> element" do
21
+ @sitemap.get.match('http://www.sitemaps.org/schemas/sitemap/0.9').should_not be_nil
22
+ end
23
+
24
+ it "should have the right number of <url> elements" do
25
+ doc = Nokogiri::XML::Document.parse @sitemap.get
26
+ doc.css("url").size.should == 3
27
+ end
28
+
29
+ describe "<url> element" do
30
+
31
+ it "should have the right <loc> element" do
32
+ doc = Nokogiri::XML::Document.parse @sitemap.get
33
+ list = doc.css("url loc").to_a
34
+ list = list.map { |e| e.inner_html }
35
+ list.include?('a.html').should be_true
36
+ list.include?('b.html').should be_true
37
+ list.include?('c.html').should be_true
38
+ end
39
+
40
+ end
41
+
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genit
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.99'
4
+ version: '1.0'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-25 00:00:00.000000000 +02:00
12
+ date: 2011-10-02 00:00:00.000000000 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: coco
17
- requirement: &68826960 !ruby/object:Gem::Requirement
17
+ requirement: &72352700 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.4.2
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *68826960
25
+ version_requirements: *72352700
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: nokogiri
28
- requirement: &68826590 !ruby/object:Gem::Requirement
28
+ requirement: &72352350 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.4.6
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *68826590
36
+ version_requirements: *72352350
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bluecloth
39
- requirement: &68826230 !ruby/object:Gem::Requirement
39
+ requirement: &72351960 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 2.1.0
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *68826230
47
+ version_requirements: *72351960
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: clamp
50
- requirement: &68825890 !ruby/object:Gem::Requirement
50
+ requirement: &72351550 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: 0.2.2
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *68825890
58
+ version_requirements: *72351550
59
59
  description: ! "Genit builds a **static web site**, that is a web site without server
60
60
  side \nprograming language and database. The site consists only of xhtml code (+
61
61
  css and medias) and \neventually of javascript. It is a command line framework,
@@ -68,6 +68,7 @@ executables:
68
68
  extensions: []
69
69
  extra_rdoc_files: []
70
70
  files:
71
+ - lib/genit/project/pages_finder.rb
71
72
  - lib/genit/project/rss_feed.rb
72
73
  - lib/genit/project/project_creator.rb
73
74
  - lib/genit/project/page_compiler.rb
@@ -77,6 +78,7 @@ files:
77
78
  - lib/genit/builders/menu_builder.rb
78
79
  - lib/genit/builders/builder_base.rb
79
80
  - lib/genit/builders/script_builder.rb
81
+ - lib/genit/builders/relativizer.rb
80
82
  - lib/genit/builders/img_builder.rb
81
83
  - lib/genit/builders/body_link_builder.rb
82
84
  - lib/genit/tags.rb
@@ -84,6 +86,7 @@ files:
84
86
  - lib/genit/documents/html_document.rb
85
87
  - lib/genit/documents/xml_document.rb
86
88
  - lib/genit/documents/fragment.rb
89
+ - lib/genit/documents/sitemap.rb
87
90
  - lib/genit/documents/document_writer.rb
88
91
  - lib/genit/utils/file_writer.rb
89
92
  - lib/genit/utils/news_utils.rb
@@ -127,6 +130,8 @@ files:
127
130
  - spec/helper.rb
128
131
  - spec/html_document_spec.rb
129
132
  - spec/builder_base_spec.rb
133
+ - spec/sitemap_spec.rb
134
+ - spec/news_utils_spec.rb
130
135
  - spec/nokogiri_spec.rb
131
136
  - spec/project_creator_spec.rb
132
137
  - spec/extensions_spec.rb
@@ -145,6 +150,7 @@ files:
145
150
  - spec/class_news_tag_spec.rb
146
151
  - spec/page_compiler_spec.rb
147
152
  - spec/class_tag_spec.rb
153
+ - spec/pages_finder_spec.rb
148
154
  - spec/xml_document_spec.rb
149
155
  - VERSION
150
156
  - NEWS