genit 0.9 → 0.99

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 CHANGED
@@ -1,3 +1,8 @@
1
+ v0.99 2011-09-25
2
+
3
+ * Genit create an RSS feed for your news articles
4
+
5
+
1
6
  v0.9 2011-09-04
2
7
 
3
8
  * You can add news to your site with ease
data/TODO CHANGED
@@ -1,45 +1,3 @@
1
1
 
2
2
 
3
3
 
4
-
5
- BUG
6
- ==================
7
-
8
-
9
-
10
-
11
- LES NEWS
12
- ====================
13
-
14
- D'abord simple, en html et en markdown:
15
-
16
- <genit class="news" number="4" />
17
- <genit class="news" />
18
-
19
-
20
- Puis avec un wrapper:
21
-
22
- <genit class="news" number="4" wrapper="a_news" />
23
- <genit class="news" wrapper="a_news" />
24
-
25
-
26
- TAG HERE & WHAT remplacent var
27
- ===============================
28
-
29
- DOSSIER PUBLIC
30
- ================================
31
-
32
- SCRIPTS
33
- =============================
34
-
35
- Les liens <img src> doivent être relativisés (comme les <a>)
36
- ============================================================
37
-
38
- les scripts doivent être relativisés
39
- ==========================================================
40
-
41
- switch --empty pour commande create
42
- ======================================
43
-
44
- supprimer le contenu de www/ avant compilation
45
- ==================================================
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9
1
+ 0.99
@@ -2,3 +2,4 @@
2
2
  require 'genit/project/project_creator'
3
3
  require 'genit/project/compiler'
4
4
  require 'genit/project/page_compiler'
5
+ require 'genit/project/rss_feed'
@@ -41,9 +41,8 @@ module Genit
41
41
 
42
42
  def compile_site
43
43
  compile_pages
44
- FileUtils.cp_r File.join(@working_dir, 'styles'), File.join(@working_dir, 'www')
45
- FileUtils.cp_r File.join(@working_dir, 'public'), File.join(@working_dir, 'www')
46
- FileUtils.cp_r File.join(@working_dir, 'scripts'), File.join(@working_dir, 'www')
44
+ copy_static_content
45
+ create_rss_feed
47
46
  end
48
47
 
49
48
  def compile_pages
@@ -65,6 +64,20 @@ module Genit
65
64
  doc_writer.save_as_xhtml @page, @filename
66
65
  end
67
66
 
67
+ def copy_static_content
68
+ destination = File.join(@working_dir, 'www')
69
+ FileUtils.cp_r File.join(@working_dir, 'styles'), destination
70
+ FileUtils.cp_r File.join(@working_dir, 'public'), destination
71
+ FileUtils.cp_r File.join(@working_dir, 'scripts'), destination
72
+ end
73
+
74
+ def create_rss_feed
75
+ all_news_files = Dir.glob(File.join(@working_dir, 'news', '*')).sort.reverse
76
+ config_file = YAML.load_file(File.join(@working_dir, '.config'))
77
+ return unless config_file[:rss]
78
+ RssFeed.new(@working_dir, all_news_files, config_file).generate_rss
79
+ end
80
+
68
81
  end
69
82
 
70
83
  end
@@ -37,12 +37,12 @@ module Genit
37
37
  # ai un jour besoin de faire une boucle du genre :
38
38
  # "Tant qu'il reste des tags"
39
39
  2.times { replace_all_genit_tags }
40
-
41
- builder = BodyLinkBuilder.new @template
42
- @template = builder.build_for_page @filename
43
-
44
- builder = ImgBuilder.new @template
45
- @template = builder.build_for_page @filename
40
+ build BodyLinkBuilder
41
+ build ImgBuilder
42
+ end
43
+
44
+ def build a_class
45
+ @template = a_class.new(@template).build_for_page(@filename)
46
46
  end
47
47
 
48
48
  def replace_all_genit_tags
@@ -1,6 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  require "fileutils"
4
+ require "yaml"
4
5
 
5
6
  module Genit
6
7
 
@@ -13,7 +14,7 @@ module Genit
13
14
  # doctype - The String document type definition.
14
15
  # empty - A Boolean telling if we produce a smoke test or not.
15
16
  def initialize name, doctype, empty
16
- @name = name
17
+ @project_name = name
17
18
  @doctype = doctype
18
19
  @empty = empty
19
20
  end
@@ -33,16 +34,34 @@ module Genit
33
34
  private
34
35
 
35
36
  def create_the_project
36
- FileUtils.makedirs @name
37
- create_dirs ['fragments', 'news', 'pages', 'scripts', 'styles', 'templates', 'www',
37
+ create_the_project_folders
38
+ copy_the_project_files
39
+ create_the_project_config
40
+ end
41
+
42
+ def create_the_project_folders
43
+ FileUtils.makedirs @project_name
44
+ create_subfolders ['fragments', 'news', 'pages', 'scripts', 'styles', 'templates', 'www',
38
45
  'styles/alsa', 'styles/yui', 'styles/images', 'public']
46
+ end
47
+
48
+ def copy_the_project_files
39
49
  copy_main_template
40
50
  copy_files ['templates/menu.html', 'styles/handheld.css', 'styles/print.css',
41
51
  'styles/alsa/all.css', 'styles/yui/all.css', 'styles/yui/base.css',
42
52
  'styles/yui/fonts.css', 'styles/yui/reset.css']
43
53
  copy_index
44
54
  copy_screen_css
45
- FileUtils.touch "#{@name}/.genit"
55
+ end
56
+
57
+ def create_the_project_config
58
+ FileUtils.touch "#{@project_name}/.genit"
59
+ config_file = { :address => 'http://www.example.com',
60
+ :rss => true,
61
+ :rss_title => 'RSS TITLE',
62
+ :rss_description => 'RSS DESCRIPTION'}.to_yaml
63
+ dest = File.join @project_name, '.config'
64
+ File.open(dest, "w") {|out| out.puts config_file }
46
65
  end
47
66
 
48
67
  # Create some subfolders inside the project folder.
@@ -51,13 +70,13 @@ module Genit
51
70
  #
52
71
  # Examples
53
72
  #
54
- # create_dirs ['styles', 'scripts']
73
+ # create_subfolders ['styles', 'scripts']
55
74
  #
56
- # create_dirs ['styles/css/alsa', 'styles/css/yui', 'styles/css/images']
75
+ # create_subfolders ['styles/css/alsa', 'styles/css/yui', 'styles/css/images']
57
76
  #
58
77
  # Returns nothing.
59
- def create_dirs a_array
60
- a_array.each {|dir| FileUtils.makedirs File.join(@name, dir) }
78
+ def create_subfolders a_array
79
+ a_array.each {|dir| FileUtils.makedirs File.join(@project_name, dir) }
61
80
  end
62
81
 
63
82
  # Copy files to project.
@@ -72,13 +91,14 @@ module Genit
72
91
  def copy_files a_array
73
92
  a_array.each do |file|
74
93
  src = File.join $GENIT_PATH, 'data', file
75
- dest = File.join @name, file
94
+ dest = File.join @project_name, file
76
95
  FileUtils.cp src, dest
77
96
  end
78
97
  end
79
98
 
99
+ # @TODO document
80
100
  def copy_index
81
- dest = File.join @name, 'pages/index.html'
101
+ dest = File.join @project_name, 'pages/index.html'
82
102
  if @empty
83
103
  src = File.join $GENIT_PATH, 'data/pages/index2.html'
84
104
  else
@@ -87,8 +107,9 @@ module Genit
87
107
  FileUtils.cp src, dest
88
108
  end
89
109
 
110
+ # @TODO document
90
111
  def copy_screen_css
91
- dest = File.join @name, 'styles/screen.css'
112
+ dest = File.join @project_name, 'styles/screen.css'
92
113
  if @empty
93
114
  FileUtils.touch dest
94
115
  else
@@ -97,17 +118,20 @@ module Genit
97
118
  end
98
119
  end
99
120
 
121
+ # @TODO document
100
122
  def copy_main_template
101
- dest = File.join @name, 'templates', 'main.html'
123
+ dest = File.join @project_name, 'templates', 'main.html'
102
124
  copy_first_part dest
103
125
  ProjectCreator.append_last_part dest
104
126
  end
105
127
 
128
+ # @TODO document
106
129
  def copy_first_part dest
107
130
  src = File.join $GENIT_PATH, 'data', 'templates', @doctype
108
131
  FileUtils.cp src, dest
109
132
  end
110
133
 
134
+ # @TODO document
111
135
  def self.append_last_part dest
112
136
  src = File.join $GENIT_PATH, 'data', 'templates', 'main.html'
113
137
  content = File.open(src, "r").read
@@ -0,0 +1,97 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'rss/maker'
4
+
5
+ module Genit
6
+
7
+ # RssFeed could generate the RSS (version 2.0) file of the project.
8
+ # To generate the RSS file, we need data from the project config
9
+ # file (.config) and the list of the news.
10
+ class RssFeed
11
+
12
+ # Public: Constructor.
13
+ #
14
+ # working_dir - The String working directory, where live the project.
15
+ # news_files - An Array filled with the full path name
16
+ # of the news files
17
+ # config - A Hash representing the project config file (.config)
18
+ def initialize working_dir, news_files, config
19
+ @working_dir = working_dir
20
+ @news_files = news_files
21
+ @config = config
22
+ @destination = File.join(@working_dir, 'www', 'rss.xml')
23
+ end
24
+
25
+ # Public: Generate the RSS file (named rss.xml) at the web site
26
+ # root (www/).
27
+ def generate_rss
28
+ content = RSS::Maker.make("2.0") do |feed|
29
+ RssFeedMeta.fill feed, @config
30
+ RssFeedItems.new(feed, @news_files, @config).fill
31
+ end
32
+ File.open(@destination, "w") { |file| file.write(content) }
33
+ end
34
+
35
+ end
36
+
37
+ # Meta data of an RSS Field
38
+ class RssFeedMeta
39
+ def self.fill feed, config
40
+ channel = feed.channel
41
+ channel.title = config[:rss_title]
42
+ channel.link = config[:address]
43
+ channel.description = config[:rss_description]
44
+ feed.items.do_sort = true
45
+ end
46
+ end
47
+
48
+ # Items of an RSS Field
49
+ class RssFeedItems
50
+
51
+ def initialize feed, news_files, config
52
+ @feed = feed
53
+ @news_files = news_files
54
+ @config = config
55
+ end
56
+
57
+ def fill
58
+ @news_files.each do |news|
59
+ item = @feed.items.new_item
60
+ item.title = RssFeedItemTitle.new(news).title
61
+ item.link = @config[:address]
62
+ item.date = Time.parse(NewsUtils.get_date_from_filename(news))
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ # Retrieve the title element of an item element of an RSS feed
69
+ # from a news article.
70
+ class RssFeedItemTitle
71
+
72
+ # Public: Get the first title content from a news article.
73
+ #
74
+ # We first search for <h1> header level, then <h2>, etc to <h6>.
75
+ # If the news article doesn't contains any <h*> element, the
76
+ # title() method returns the ISO date string (yyyy-mm-dd) found
77
+ # in the news article pathname.
78
+ #
79
+ # Returns the String title of the news article.
80
+ attr_reader :title
81
+
82
+ def initialize news_pathname
83
+ @news_pathname = news_pathname
84
+ @title = NewsUtils.get_date_from_filename @news_pathname
85
+ doc = HtmlDocument.open_fragment(@news_pathname)
86
+ ('h1'..'h6').each do |header|
87
+ tag = doc.at_css(header)
88
+ if tag
89
+ @title = tag.inner_html
90
+ break
91
+ end
92
+ end
93
+ end
94
+
95
+ end
96
+
97
+ end
@@ -26,25 +26,22 @@ module Genit
26
26
 
27
27
  def news_content
28
28
  news_string = ''
29
- news_files.each do |file|
30
- doc = HtmlDocument.open_as_string file
31
- if @tag['wrapper']
32
- news_string += "<div class='#{@tag['wrapper']}'>" + doc.to_s + '</div>'
33
- else
34
- news_string += doc.to_s
35
- end
36
- end
29
+ news_files.each { |file| news_string += process_the_news(file) }
37
30
  news_string
38
31
  end
39
32
 
40
33
  def news_files
41
34
  files = Dir.glob(File.join(@working_dir, 'news', '*')).sort.reverse
42
35
  number = @tag['number']
43
- if number
44
- files[0...(number).to_i]
45
- else
46
- files
47
- end
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
48
45
  end
49
46
 
50
47
  end
@@ -1,2 +1,3 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require 'genit/utils/file_writer'
3
+ require 'genit/utils/news_utils'
@@ -0,0 +1,14 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Genit
4
+
5
+ # Utily methods for a news (an article).
6
+ class NewsUtils
7
+
8
+ def self.get_date_from_filename filename
9
+ File.basename(filename).gsub(/\..*$/, '')
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -22,14 +22,14 @@ describe Compiler do
22
22
 
23
23
  it "should build an index.html page in www" do
24
24
  @compiler.compile
25
- File.exist?('spec/project-name/www/index.html').should == true
25
+ File.exist?('spec/project-name/www/index.html').should be_true
26
26
  end
27
27
 
28
28
  it "should build two pages" do
29
29
  write_file 'pages/doc.html', '<h1>documentation</h1>'
30
30
  @compiler.compile
31
- File.exist?('spec/project-name/www/index.html').should == true
32
- File.exist?('spec/project-name/www/doc.html').should == true
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
33
  end
34
34
 
35
35
  it "should copy the styles/ into www/" do
@@ -48,29 +48,41 @@ describe Compiler do
48
48
  compiler.compile
49
49
  end
50
50
 
51
- it "should allow template to include a fragment (Bug#37)" do
52
- # add a fragment
53
- File.open('spec/project-name/fragments/footer.html', "w") {|out| out.puts '<p>footer</p>' }
54
- # replace main.html
55
- main = %q{
56
- <?xml version="1.0" encoding="UTF-8"?>
57
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
58
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
59
- <head>
60
- <title>Genit - Static web site framework</title>
61
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
62
- <link rel="stylesheet" type="text/css" media="all" href="styles/alsa/all.css" />
63
- <link rel="stylesheet" type="text/css" media="screen" href="styles/screen.css" />
64
- <link rel="stylesheet" type="text/css" media="print" href="styles/print.css" />
65
- </head>
66
- <body>
67
- <genit class="menu" />
68
- <genit class="pages" />
69
- <genit class="fragment" file="footer.html"/>
70
- </body>
71
- </html>}
72
- File.open('spec/project-name/templates/main.html', "w") {|out| out.puts main }
73
- lambda {@compiler.compile}.should_not raise_error
51
+ describe "RSS feed" do
52
+
53
+ it "should build the rss.xml file" do
54
+ File.exist?('spec/project-name/www/rss.xml').should be_true
55
+ end
56
+
57
+ end
58
+
59
+ describe "BUGS" do
60
+
61
+ it "should allow template to include a fragment (Bug#37)" do
62
+ # add a fragment
63
+ File.open('spec/project-name/fragments/footer.html', "w") {|out| out.puts '<p>footer</p>' }
64
+ # replace main.html
65
+ main = %q{
66
+ <?xml version="1.0" encoding="UTF-8"?>
67
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
68
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
69
+ <head>
70
+ <title>Genit - Static web site framework</title>
71
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
72
+ <link rel="stylesheet" type="text/css" media="all" href="styles/alsa/all.css" />
73
+ <link rel="stylesheet" type="text/css" media="screen" href="styles/screen.css" />
74
+ <link rel="stylesheet" type="text/css" media="print" href="styles/print.css" />
75
+ </head>
76
+ <body>
77
+ <genit class="menu" />
78
+ <genit class="pages" />
79
+ <genit class="fragment" file="footer.html"/>
80
+ </body>
81
+ </html>}
82
+ File.open('spec/project-name/templates/main.html', "w") {|out| out.puts main }
83
+ lambda {@compiler.compile}.should_not raise_error
84
+ end
85
+
74
86
  end
75
87
 
76
88
  end
@@ -29,6 +29,34 @@ describe ProjectCreator do
29
29
  File.exist?('spec/project-name/.genit').should == true
30
30
  end
31
31
 
32
+ it "should create a config file" do
33
+ File.exist?('spec/project-name/.config').should == true
34
+ end
35
+
36
+ end
37
+
38
+ describe "Config file" do
39
+
40
+ before :each do
41
+ @config_file = YAML.load_file('spec/project-name/.config')
42
+ end
43
+
44
+ it "should have an address value of 'http://www.example.com'" do
45
+ @config_file[:address].should == 'http://www.example.com'
46
+ end
47
+
48
+ it "should have an rss value at true" do
49
+ @config_file[:rss].should be_true
50
+ end
51
+
52
+ it "should have an rss_title value of 'RSS TITLE'" do
53
+ @config_file[:rss_title].should == 'RSS TITLE'
54
+ end
55
+
56
+ it "should have an rss_description value of 'RSS DESCRIPTION'" do
57
+ @config_file[:rss_description].should == 'RSS DESCRIPTION'
58
+ end
59
+
32
60
  end
33
61
 
34
62
  describe "Folder structure" do
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.9'
4
+ version: '0.99'
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-04 00:00:00.000000000 +02:00
12
+ date: 2011-09-25 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: &72980010 !ruby/object:Gem::Requirement
17
+ requirement: &68826960 !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: *72980010
25
+ version_requirements: *68826960
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: nokogiri
28
- requirement: &72979620 !ruby/object:Gem::Requirement
28
+ requirement: &68826590 !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: *72979620
36
+ version_requirements: *68826590
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bluecloth
39
- requirement: &72979050 !ruby/object:Gem::Requirement
39
+ requirement: &68826230 !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: *72979050
47
+ version_requirements: *68826230
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: clamp
50
- requirement: &72978470 !ruby/object:Gem::Requirement
50
+ requirement: &68825890 !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: *72978470
58
+ version_requirements: *68825890
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/rss_feed.rb
71
72
  - lib/genit/project/project_creator.rb
72
73
  - lib/genit/project/page_compiler.rb
73
74
  - lib/genit/project/compiler.rb
@@ -85,6 +86,7 @@ files:
85
86
  - lib/genit/documents/fragment.rb
86
87
  - lib/genit/documents/document_writer.rb
87
88
  - lib/genit/utils/file_writer.rb
89
+ - lib/genit/utils/news_utils.rb
88
90
  - lib/genit/builders.rb
89
91
  - lib/genit/utils.rb
90
92
  - lib/genit/tags/class_menu_tag.rb