genit 0.5 → 0.9

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.
Files changed (53) hide show
  1. data/NEWS +20 -0
  2. data/TODO +40 -4
  3. data/VERSION +1 -1
  4. data/bin/genit +10 -2
  5. data/data/pages/index.html +10 -11
  6. data/data/pages/index2.html +1 -0
  7. data/data/styles/screen.css +12 -3
  8. data/data/templates/html_5 +5 -0
  9. data/data/templates/main.html +0 -6
  10. data/data/templates/xhtml_1.0_strict +5 -0
  11. data/data/templates/xhtml_1.0_transitional +5 -0
  12. data/lib/genit.rb +5 -18
  13. data/lib/genit/builders.rb +8 -0
  14. data/lib/genit/{body_link_builder.rb → builders/body_link_builder.rb} +7 -3
  15. data/lib/genit/{builder.rb → builders/builder.rb} +0 -0
  16. data/lib/genit/{builder_base.rb → builders/builder_base.rb} +0 -0
  17. data/lib/genit/{head_link_builder.rb → builders/head_link_builder.rb} +5 -0
  18. data/lib/genit/builders/img_builder.rb +39 -0
  19. data/lib/genit/{menu_builder.rb → builders/menu_builder.rb} +0 -0
  20. data/lib/genit/builders/script_builder.rb +37 -0
  21. data/lib/genit/documents.rb +5 -0
  22. data/lib/genit/{document_writer.rb → documents/document_writer.rb} +0 -0
  23. data/lib/genit/{fragment.rb → documents/fragment.rb} +0 -0
  24. data/lib/genit/{html_document.rb → documents/html_document.rb} +0 -0
  25. data/lib/genit/{xml_document.rb → documents/xml_document.rb} +0 -0
  26. data/lib/genit/extensions.rb +2 -44
  27. data/lib/genit/extensions/nokogiri_extension.rb +37 -0
  28. data/lib/genit/extensions/string_extension.rb +17 -0
  29. data/lib/genit/project.rb +4 -0
  30. data/lib/genit/{compiler.rb → project/compiler.rb} +12 -0
  31. data/lib/genit/{page_compiler.rb → project/page_compiler.rb} +21 -2
  32. data/lib/genit/project/project_creator.rb +119 -0
  33. data/lib/genit/tags.rb +9 -0
  34. data/lib/genit/tags/class_fragment_tag.rb +30 -0
  35. data/lib/genit/tags/class_menu_tag.rb +36 -0
  36. data/lib/genit/tags/class_news_tag.rb +52 -0
  37. data/lib/genit/tags/class_pages_tag.rb +34 -0
  38. data/lib/genit/tags/class_tag.rb +38 -0
  39. data/lib/genit/{var_tag.rb → tags/here_tag.rb} +10 -5
  40. data/lib/genit/{tag.rb → tags/tag.rb} +0 -0
  41. data/lib/genit/{tag_processor.rb → tags/tag_processor.rb} +4 -3
  42. data/lib/genit/utils.rb +2 -0
  43. data/lib/genit/{file_writer.rb → utils/file_writer.rb} +0 -0
  44. data/spec/class_news_tag_spec.rb +36 -0
  45. data/spec/class_tag_spec.rb +13 -0
  46. data/spec/compiler_spec.rb +1 -1
  47. data/spec/menu_builder_spec.rb +0 -14
  48. data/spec/page_compiler_spec.rb +3 -4
  49. data/spec/project_creator_spec.rb +6 -2
  50. data/spec/tag_processor_spec.rb +8 -0
  51. metadata +46 -27
  52. data/lib/genit/class_tag.rb +0 -66
  53. data/lib/genit/project_creator.rb +0 -72
@@ -5,7 +5,7 @@ module Genit
5
5
  # A Genit tag that represents a variable.
6
6
  # For example, in the template you have: <genit var="page_title"/>,
7
7
  # and in the page you have: <genit var="page_title">My Title</genit>.
8
- class VarTag < Tag
8
+ class HereTag < Tag
9
9
 
10
10
  # Public: Constructor.
11
11
  #
@@ -29,14 +29,19 @@ module Genit
29
29
  private
30
30
 
31
31
  def get_css_rule
32
- var_name = @tag['var']
33
- "genit[var='#{var_name}']"
32
+ var_name = @tag['here']
33
+ "genit[here='#{var_name}']"
34
34
  end
35
35
 
36
36
  def get_variable_value
37
37
  filename = File.join(@working_dir, 'pages', @filename)
38
- doc = HtmlDocument.open filename
39
- doc.at_css("genit[var='#{@tag['var']}']").inner_html
38
+ doc = HtmlDocument.open_fragment filename
39
+ elem = doc.at_css("genit[what='#{@tag['here']}']")
40
+ if elem.nil?
41
+ ""
42
+ else
43
+ elem.inner_html
44
+ end
40
45
  end
41
46
 
42
47
  end
File without changes
@@ -17,10 +17,11 @@ module Genit
17
17
  @template = template
18
18
  if tag.genit_class?
19
19
  @tag = ClassTag.new(@working_dir, @template, @filename, tag)
20
- elsif tag.genit_var?
21
- @tag = VarTag.new(@working_dir, @template, @filename, tag)
20
+ elsif tag.genit_here?
21
+ @tag = HereTag.new(@working_dir, @template, @filename, tag)
22
22
  else
23
- raise RuntimeError
23
+ puts "Genit aborted! Unknown tag: #{tag}"
24
+ exit 1
24
25
  end
25
26
  end
26
27
 
@@ -0,0 +1,2 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'genit/utils/file_writer'
File without changes
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require './spec/helper'
4
+
5
+ describe ClassNewsTag do
6
+
7
+ after :all do
8
+ clean_test_repository
9
+ end
10
+
11
+ def create_sample_project
12
+ FileUtils.makedirs('spec/project-name/news')
13
+ File.open('spec/project-name/news/2011-01-01.html', "w") {|out| out.puts '<h1>2011-01-01</h1>' }
14
+ File.open('spec/project-name/news/2011-02-02.html', "w") {|out| out.puts '<h1>2011-02-02</h1>' }
15
+ end
16
+
17
+ it "should replace all news" do
18
+ create_sample_project
19
+ template = Nokogiri::XML.fragment '<genit class="news"/>'
20
+ tag = {'class' => 'news'}
21
+ cnt = ClassNewsTag.new 'spec/project-name', template, 'mock', tag
22
+ doc = cnt.process
23
+ doc.css('h1').size.should == 2
24
+ end
25
+
26
+ it "should replace X news" do
27
+ create_sample_project
28
+ template = Nokogiri::XML.fragment '<genit class="news" number="1"/>'
29
+ tag = {'class' => 'news', 'number' => '1'}
30
+ cnt = ClassNewsTag.new 'spec/project-name', template, 'mock', tag
31
+ doc = cnt.process
32
+ doc.css('h1').size.should == 1
33
+ doc.css('h1').inner_html.should == '2011-02-02'
34
+ end
35
+
36
+ end
@@ -0,0 +1,13 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require './spec/helper'
4
+
5
+ describe ClassTag do
6
+
7
+ it "should raise error if class is unknown" do
8
+ tag = {'class' => 'unknown'}
9
+ ct = ClassTag.new 'mock', 'mock', 'mock', tag
10
+ lambda{ct.process}.should raise_error(RuntimeError)
11
+ end
12
+
13
+ end
@@ -5,7 +5,7 @@ require './spec/helper'
5
5
  describe Compiler do
6
6
 
7
7
  before :all do
8
- @project = ProjectCreator.new('spec/project-name')
8
+ @project = ProjectCreator.new('spec/project-name', 'html_5', false)
9
9
  @project.create
10
10
  @compiler = Compiler.new File.expand_path('spec/project-name')
11
11
  end
@@ -34,20 +34,6 @@ describe MenuBuilder do
34
34
  new_menu.css("ul#menu a#selected").first['href'].should == 'about.html'
35
35
  end
36
36
 
37
- #~ it "should set the menu for doc/index.html page" do
38
- #~ builder = MenuBuilder.new(@menu_doc)
39
- #~ new_menu = builder.build_for_page('doc/index.html')
40
- #~ new_menu.css("ul#menu a#selected").size.should == 1
41
- #~ new_menu.css("ul#menu a#selected").first['href'].should == '../doc/index.html'
42
- #~ end
43
- #~
44
- #~ it "should set the menu for a/b/c2.html page" do
45
- #~ builder = MenuBuilder.new(@menu_doc)
46
- #~ new_menu = builder.build_for_page('a/b/c2.html')
47
- #~ new_menu.css("ul#menu a#selected").size.should == 1
48
- #~ new_menu.css("ul#menu a#selected").first['href'].should == '../../a/b/c2.html'
49
- #~ end
50
-
51
37
  it "should set the menu for /absolute.html page" do
52
38
  builder = MenuBuilder.new(@menu_doc)
53
39
  new_menu = builder.build_for_page('/absolute.html')
@@ -11,15 +11,14 @@ describe PageCompiler do
11
11
  def create_sample_project
12
12
  FileUtils.makedirs('spec/project-name/templates')
13
13
  FileUtils.makedirs('spec/project-name/pages')
14
- File.open('spec/project-name/templates/main.html', "w") {|out| out.puts '<h1><genit var="title"/></h1>' }
15
- File.open('spec/project-name/pages/index.html', "w") {|out| out.puts '<genit var="title">My Title</genit>' }
14
+ File.open('spec/project-name/templates/main.html', "w") {|out| out.puts '<h1><genit here="title"/></h1>' }
15
+ File.open('spec/project-name/pages/index.html', "w") {|out| out.puts '<genit what="title">My Title</genit>' }
16
16
  end
17
17
 
18
18
  it "should substitute a variable" do
19
19
  create_sample_project
20
20
  pc = PageCompiler.new 'spec/project-name/', 'index.html'
21
21
  doc = pc.compile
22
-
23
22
  doc.at_css('h1').inner_html.should == 'My Title'
24
23
  end
25
24
 
@@ -29,7 +28,7 @@ describe PageCompiler do
29
28
  doc = pc.compile
30
29
 
31
30
  page = IO.read 'spec/project-name/pages/index.html'
32
- page.match('<genit var="title">My Title</genit>').should_not == nil
31
+ page.match('<genit what="title">My Title</genit>').should_not be_nil
33
32
  end
34
33
 
35
34
  end
@@ -5,7 +5,7 @@ require './spec/helper'
5
5
  describe ProjectCreator do
6
6
 
7
7
  before :all do
8
- @project = ProjectCreator.new('spec/project-name')
8
+ @project = ProjectCreator.new('spec/project-name', 'html_5', false)
9
9
  @project.create
10
10
  end
11
11
 
@@ -20,7 +20,7 @@ describe ProjectCreator do
20
20
  end
21
21
 
22
22
  it "should say it if it cannot create a project" do
23
- project = ProjectCreator.new('/root/project')
23
+ project = ProjectCreator.new('/root/project', 'html_5', false)
24
24
  $stdout.should_receive(:puts).with("Cannot create project...")
25
25
  project.create
26
26
  end
@@ -72,6 +72,10 @@ describe ProjectCreator do
72
72
  it "should create a images folder inside the styles" do
73
73
  File.exist?('spec/project-name/styles/images').should == true
74
74
  end
75
+
76
+ it "should create a public folder" do
77
+ File.exist?('spec/project-name/public').should == true
78
+ end
75
79
 
76
80
  end # "Folder structure"
77
81
 
@@ -4,5 +4,13 @@ require './spec/helper'
4
4
 
5
5
  describe TagProcessor do
6
6
 
7
+ it "should abort on unknown tag" do
8
+ doc = Nokogiri::XML.fragment('<body><genit foo="bar"/></body>')
9
+ tag = doc.at_css('genit')
10
+ STDOUT.should_receive(:puts).with("Genit aborted! Unknown tag: <genit foo=\"bar\"/>")
11
+ lambda do
12
+ TagProcessor.new('mock', 'mock', 'mock', tag)
13
+ end.should raise_error(SystemExit)
14
+ end
7
15
 
8
16
  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.5'
4
+ version: '0.9'
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-08-06 00:00:00.000000000 +02:00
12
+ date: 2011-09-04 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: &72437520 !ruby/object:Gem::Requirement
17
+ requirement: &72980010 !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: *72437520
25
+ version_requirements: *72980010
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: nokogiri
28
- requirement: &72437120 !ruby/object:Gem::Requirement
28
+ requirement: &72979620 !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: *72437120
36
+ version_requirements: *72979620
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bluecloth
39
- requirement: &72436670 !ruby/object:Gem::Requirement
39
+ requirement: &72979050 !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: *72436670
47
+ version_requirements: *72979050
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: clamp
50
- requirement: &72436180 !ruby/object:Gem::Requirement
50
+ requirement: &72978470 !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: *72436180
58
+ version_requirements: *72978470
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,26 +68,42 @@ executables:
68
68
  extensions: []
69
69
  extra_rdoc_files: []
70
70
  files:
71
- - lib/genit/head_link_builder.rb
72
- - lib/genit/project_creator.rb
73
- - lib/genit/var_tag.rb
74
- - lib/genit/html_document.rb
75
- - lib/genit/builder.rb
76
- - lib/genit/file_writer.rb
77
- - lib/genit/xml_document.rb
78
- - lib/genit/menu_builder.rb
79
- - lib/genit/tag_processor.rb
80
- - lib/genit/builder_base.rb
81
- - lib/genit/page_compiler.rb
82
- - lib/genit/fragment.rb
83
- - lib/genit/tag.rb
84
- - lib/genit/body_link_builder.rb
85
- - lib/genit/class_tag.rb
86
- - lib/genit/compiler.rb
71
+ - lib/genit/project/project_creator.rb
72
+ - lib/genit/project/page_compiler.rb
73
+ - lib/genit/project/compiler.rb
74
+ - lib/genit/builders/head_link_builder.rb
75
+ - lib/genit/builders/builder.rb
76
+ - lib/genit/builders/menu_builder.rb
77
+ - lib/genit/builders/builder_base.rb
78
+ - lib/genit/builders/script_builder.rb
79
+ - lib/genit/builders/img_builder.rb
80
+ - lib/genit/builders/body_link_builder.rb
81
+ - lib/genit/tags.rb
82
+ - lib/genit/project.rb
83
+ - lib/genit/documents/html_document.rb
84
+ - lib/genit/documents/xml_document.rb
85
+ - lib/genit/documents/fragment.rb
86
+ - lib/genit/documents/document_writer.rb
87
+ - lib/genit/utils/file_writer.rb
88
+ - lib/genit/builders.rb
89
+ - lib/genit/utils.rb
90
+ - lib/genit/tags/class_menu_tag.rb
91
+ - lib/genit/tags/class_news_tag.rb
92
+ - lib/genit/tags/class_fragment_tag.rb
93
+ - lib/genit/tags/here_tag.rb
94
+ - lib/genit/tags/class_pages_tag.rb
95
+ - lib/genit/tags/tag_processor.rb
96
+ - lib/genit/tags/tag.rb
97
+ - lib/genit/tags/class_tag.rb
87
98
  - lib/genit/extensions.rb
88
- - lib/genit/document_writer.rb
99
+ - lib/genit/documents.rb
100
+ - lib/genit/extensions/string_extension.rb
101
+ - lib/genit/extensions/nokogiri_extension.rb
89
102
  - lib/genit.rb
90
103
  - bin/genit
104
+ - data/templates/xhtml_1.0_strict
105
+ - data/templates/html_5
106
+ - data/templates/xhtml_1.0_transitional
91
107
  - data/templates/menu.html
92
108
  - data/templates/main.html
93
109
  - data/styles/handheld.css
@@ -99,6 +115,7 @@ files:
99
115
  - data/styles/yui/base.css
100
116
  - data/styles/yui/fonts.css
101
117
  - data/pages/index.html
118
+ - data/pages/index2.html
102
119
  - spec/file_writer_spec.rb
103
120
  - spec/compiler_spec.rb
104
121
  - spec/tag_processor_spec.rb
@@ -123,7 +140,9 @@ files:
123
140
  - spec/test-files/fragments/title.markdown
124
141
  - spec/test-files/fragments/d.html
125
142
  - spec/test-files/nothing.html
143
+ - spec/class_news_tag_spec.rb
126
144
  - spec/page_compiler_spec.rb
145
+ - spec/class_tag_spec.rb
127
146
  - spec/xml_document_spec.rb
128
147
  - VERSION
129
148
  - NEWS
@@ -1,66 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- module Genit
4
-
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
- class ClassTag < Tag
11
-
12
- # Public: Constructor.
13
- #
14
- # working_dir - The String working directory, where live the project.
15
- # template - The Nokogiri::XML::Document into which we process the tag.
16
- # filename - The String name of the page
17
- # tag - The tag to process as a Nokogiri::XML::Element
18
- def initialize working_dir, template, filename, tag
19
- super working_dir, template, filename, tag
20
- end
21
-
22
- # Public: Replace something in the template.
23
- #
24
- # Returns the template as a Nokogiri::XML::Document
25
- def process
26
- case @tag['class']
27
- when 'pages' then process_tag_pages
28
- when 'menu' then process_tag_menu
29
- when 'fragment' then process_fragment
30
- else
31
- raise RuntimeError
32
- end
33
- end
34
-
35
- private
36
-
37
- def process_tag_pages
38
- replace_tag_into_template! 'genit.pages', page_content
39
- end
40
-
41
- def page_content
42
- filename = File.join(@working_dir, 'pages', @filename)
43
- HtmlDocument.build_page_content filename, @working_dir
44
- end
45
-
46
- def process_tag_menu
47
- build_menu
48
- replace_tag_into_template! 'genit.menu', @menu.to_html
49
- end
50
-
51
- def build_menu
52
- menu = XmlDocument.open(File.join(@working_dir, "templates/menu.html"))
53
- builder = MenuBuilder.new(menu)
54
- @menu = builder.build_for_page(@filename)
55
- end
56
-
57
- def process_fragment
58
- file = @tag['file']
59
- fragment = HtmlDocument.build_page_content(File.join(@working_dir, 'fragments', file), @working_dir)
60
- css_rule = "genit.fragment[file='#{file}']"
61
- replace_tag_into_template! css_rule, fragment.to_s
62
- end
63
-
64
- end
65
-
66
- end
@@ -1,72 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require "fileutils"
4
-
5
- module Genit
6
-
7
- # Create a skeleton project.
8
- class ProjectCreator
9
-
10
- # Sole constructor.
11
- #
12
- # name - The String name of the future project folder.
13
- def initialize name
14
- @name = name
15
- end
16
-
17
- # Public: Create the structure of the project, that is many
18
- # files and folders.
19
- #
20
- # Returns nothing.
21
- def create
22
- begin
23
- FileUtils.makedirs @name
24
- create_dirs ['fragments', 'news', 'pages', 'scripts', 'styles', 'templates', 'www',
25
- 'styles/alsa', 'styles/yui', 'styles/images']
26
- copy_files ['templates/main.html', 'templates/menu.html',
27
- 'pages/index.html', 'styles/handheld.css', 'styles/print.css',
28
- 'styles/screen.css', 'styles/alsa/all.css', 'styles/yui/all.css', 'styles/yui/base.css',
29
- 'styles/yui/fonts.css', 'styles/yui/reset.css']
30
- FileUtils.touch "#{@name}/.genit"
31
- rescue SystemCallError
32
- puts "Cannot create project..."
33
- end
34
- end
35
-
36
- private
37
-
38
- # Create some subfolders inside the project folder.
39
- #
40
- # a_array - An Array of String subfolder names
41
- #
42
- # Examples
43
- #
44
- # create_dirs ['styles', 'scripts']
45
- #
46
- # create_dirs ['styles/css/alsa', 'styles/css/yui', 'styles/css/images']
47
- #
48
- # Returns nothing.
49
- def create_dirs a_array
50
- a_array.each {|dir| FileUtils.makedirs File.join(@name, dir) }
51
- end
52
-
53
- # Copy files to project.
54
- #
55
- # a_array - An Array of String "subfolder/file" names
56
- #
57
- # Example
58
- #
59
- # copy_files ['templates/main.html', 'pages/index.html']
60
- #
61
- # Returns nothing.
62
- def copy_files a_array
63
- a_array.each do |file|
64
- src = File.join $GENIT_PATH, 'data', file
65
- dest = File.join @name, file
66
- FileUtils.cp src, dest
67
- end
68
- end
69
-
70
- end
71
-
72
- end