genit 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/NEWS CHANGED
@@ -1,3 +1,8 @@
1
+ v0.3 2001-07-23
2
+
3
+ * You can split a page in a multitude of fragments.
4
+
5
+
1
6
  v0.2 2011-07-02
2
7
 
3
8
  * Globally styling your site
@@ -2,7 +2,9 @@ Genit
2
2
  ================
3
3
 
4
4
  Genit builds a **static web site**, that is a web site without server side programing language
5
- and database. A site consists only of xhtml code (+ css and medias) and eventually of javascript.
5
+ and database. A genit site consists only of xhtml code (+ css, medias and eventually javascript).
6
+
7
+ There is no needs to know the Ruby language.
6
8
 
7
9
  The project is in early development stage, see
8
10
  [project guidelines](https://github.com/lkdjiin/genit/blob/master/project_guidelines.markdown).
@@ -37,6 +39,7 @@ First install ruby and rubygem (if there are not installed on your system) then:
37
39
 
38
40
  gem install genit
39
41
 
42
+ All other dependencies will be downloaded and installed automatically.
40
43
 
41
44
  Usage
42
45
  --------------------------
data/TODO CHANGED
@@ -1,20 +1,26 @@
1
- v0.2
2
- ====
1
+ release v0.3
3
2
 
4
- release
5
3
 
6
4
 
7
- web site for genit
5
+ smoke test
8
6
 
9
- announce
7
+ mettre un fichier caché pour savoir qu'on a affaire à un projet Genit.
8
+
9
+ option --version et --help (utiliser un framework cli)
10
+
11
+ commencer documentation
12
+
13
+ release v0.4
10
14
 
11
- news
12
15
 
13
- release
14
16
 
15
- ------------------
16
- i18n
17
17
 
18
- per page style
18
+ web site for genit
19
+
20
+ announce site (freshmeat et blog)
21
+
22
+ news
23
+
24
+ release v0.5
19
25
 
20
- per page script
26
+ Trouver / penser à / un framework de test xhtml/css
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2
1
+ 0.3
@@ -1,13 +1,15 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
+ require 'genit/extensions'
3
4
  require 'genit/project_creator'
4
-
5
5
  require 'genit/html_document'
6
6
  require 'genit/xml_document'
7
+ require 'genit/file_writer'
7
8
  require 'genit/document_writer'
8
9
  require 'genit/compiler'
9
10
  require 'genit/page_compiler'
10
11
  require 'genit/builder'
12
+ require 'genit/fragment'
11
13
 
12
14
  module Genit
13
15
  end
@@ -32,13 +32,13 @@ module Genit
32
32
 
33
33
  def compile_page
34
34
  pc = PageCompiler.new @working_dir, @filename
35
- @template = pc.compile
35
+ @page = pc.compile
36
36
  save_file_as_html
37
37
  end
38
38
 
39
39
  def save_file_as_html
40
40
  doc_writer = DocumentWriter.new @working_dir
41
- doc_writer.save_as_html @template, @filename
41
+ doc_writer.save_as_html @page, @filename
42
42
  end
43
43
 
44
44
  end
@@ -19,10 +19,13 @@ module Genit
19
19
  # document - A Nokogiri::HTML or Nokogiri::XML document
20
20
  # filename - The String name of the future saved document
21
21
  def save_as_html document, filename
22
- filename.gsub! /\.markdown$/, '.html'
23
- File.open(File.join(@working_dir, 'www', filename), "w") do |out|
24
- out.puts document.to_html
25
- end
22
+ FileWriter.write document.to_html, get_full_path(filename.force_html_extension)
23
+ end
24
+
25
+ private
26
+
27
+ def get_full_path filename
28
+ File.join(@working_dir, 'www', filename)
26
29
  end
27
30
 
28
31
  end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ class String
4
+
5
+ def force_html_extension
6
+ self.gsub /markdown$/, 'html'
7
+ end
8
+
9
+ def force_html_extension!
10
+ self.gsub! /markdown$/, 'html'
11
+ end
12
+
13
+ def markdown_ext?
14
+ self.end_with?('.markdown')
15
+ end
16
+
17
+ end
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'fileutils'
4
+
5
+ module Genit
6
+
7
+ # Write a file on disk.
8
+ class FileWriter
9
+
10
+ def self.write content, full_path
11
+ File.open(full_path, "w") {|out| out.puts content }
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,49 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Genit
4
+
5
+ # Replace each fragment in a page.
6
+ class Fragment
7
+
8
+ # Public: Constructor.
9
+ #
10
+ # file - Full String filename of the page.
11
+ # working_dir - The String working directory, where live the project.
12
+ def initialize file, working_dir
13
+ @page = HtmlDocument.open_fragment file
14
+ @working_dir = working_dir
15
+ HtmlDocument.genit_tags_from(@page).each do |tag|
16
+ case tag['class']
17
+ when 'fragment'
18
+ @file = tag['file']
19
+ replace_fragment
20
+ end
21
+ end
22
+ end
23
+
24
+ # Public: Get the page in html format.
25
+ #
26
+ # Returns the html code of the page as a String.
27
+ def to_html
28
+ @page.to_html
29
+ end
30
+
31
+ private
32
+
33
+ def replace_fragment
34
+ builder = Builder.new(@page)
35
+ @page = builder.replace(css_rule, content)
36
+ end
37
+
38
+ def css_rule
39
+ "genit.fragment[file='#{@file}']"
40
+ end
41
+
42
+ def content
43
+ full_path = File.join(@working_dir, 'fragments', @file)
44
+ HtmlDocument.open_as_string(full_path)
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -8,7 +8,9 @@ module Genit
8
8
  # Open an html file in various format.
9
9
  class HtmlDocument
10
10
 
11
- # Public: Open a html document.
11
+ # Public: Open an entire html document.
12
+ # If the file does not contain a <bogy> tag, a doctype, etc, they will be
13
+ # automatically added.
12
14
  #
13
15
  # file - Full path String filename.
14
16
  #
@@ -17,20 +19,48 @@ module Genit
17
19
  Nokogiri::HTML(File.open(file))
18
20
  end
19
21
 
20
- # Public: Open a html or markdown file as a string.
22
+ # Public: Open a fragment of html document.
23
+ #
24
+ # file - Full path String filename.
25
+ #
26
+ # Returns a Nokogiri::HTML document.
27
+ def self.open_fragment file
28
+ string = IO.read file
29
+ Nokogiri::HTML.fragment string
30
+ end
31
+
32
+ # Public: Open a file as a string.
21
33
  #
22
34
  # file - Full path String name of a html or markdown file.
23
35
  #
24
36
  # Returns a String.
25
37
  def self.open_as_string file
26
38
  string = IO.read file
27
- string = BlueCloth.new(string).to_html if file.end_with? '.markdown'
28
- string
39
+ if file.markdown_ext?
40
+ BlueCloth.new(string).to_html
41
+ else
42
+ string
43
+ end
44
+ end
45
+
46
+ # Public: Open a file as a string, taking care of fragment tags.
47
+ # All fragment tags are replaced by a new content.
48
+ #
49
+ # file - Full path String name of a html or markdown file.
50
+ #
51
+ # Returns a String.
52
+ def self.build_page_content(file, working_dir)
53
+ # TODO éviter le working_dir
54
+ if file.markdown_ext?
55
+ BlueCloth.new(IO.read(file)).to_html
56
+ else
57
+ Fragment.new(file, working_dir).to_html
58
+ end
29
59
  end
30
60
 
31
61
  # Public: Get the list of <genit> tag in a document.
32
62
  #
33
- # file - Nokogiri::HTML document.
63
+ # file - Nokogiri::HTML or Nokogiri::XML document.
34
64
  #
35
65
  # Returns a list of Nokogiri::XML::NodeSet.
36
66
  def self.genit_tags_from file
@@ -37,9 +37,13 @@ module Genit
37
37
 
38
38
  # Remplace la page au sein du template
39
39
  def tag_pages
40
- @page_content = HtmlDocument.open_as_string(File.join(@working_dir, 'pages', @filename))
41
40
  builder = Builder.new(@template)
42
- @template = builder.replace('genit.pages', @page_content)
41
+ @template = builder.replace('genit.pages', page_content)
42
+ end
43
+
44
+ def page_content
45
+ filename = File.join(@working_dir, 'pages', @filename)
46
+ HtmlDocument.build_page_content filename, @working_dir
43
47
  end
44
48
 
45
49
  def tag_menu
@@ -21,7 +21,7 @@ module Genit
21
21
  def create
22
22
  begin
23
23
  FileUtils.makedirs @name
24
- create_dirs ['news', 'pages', 'scripts', 'styles', 'templates', 'www']
24
+ create_dirs ['fragments', 'news', 'pages', 'scripts', 'styles', 'templates', 'www']
25
25
  create_dirs ['styles/alsa', 'styles/yui', 'styles/images']
26
26
  copy_files ['templates/main.html', 'templates/menu.html',
27
27
  'pages/index.html', 'styles/handheld.css', 'styles/print.css',
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require './spec/helper'
4
+
5
+ describe "Standard class String extensions" do
6
+
7
+ it "should replace a markdown file ext" do
8
+ string = "file.markdown"
9
+ result = string.force_html_extension
10
+ result.should == "file.html"
11
+ end
12
+
13
+ it "should replace a markdown file ext !" do
14
+ string = "file.markdown"
15
+ string.force_html_extension!
16
+ string.should == "file.html"
17
+ end
18
+
19
+ it "should not replace an other file ext" do
20
+ string = "file.txt"
21
+ string.force_html_extension!
22
+ string.should == "file.txt"
23
+ end
24
+
25
+ it "should say if it has a markdown file extension" do
26
+ string = "file.markdown"
27
+ string.markdown_ext?.should be_true
28
+ end
29
+
30
+ it "should say if it has not a markdown file extension" do
31
+ string = "file.other"
32
+ string.markdown_ext?.should be_false
33
+ end
34
+
35
+ end
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require './spec/helper'
4
+
5
+ describe Fragment do
6
+
7
+ it "should replace one fragment tag" do
8
+ fragment = Fragment.new("spec/test-files/fragment.html", 'spec/test-files')
9
+ fragment.to_html.start_with?('<h1>title</h1>').should be_true
10
+ end
11
+
12
+ it "should replace one fragment tag among other tags" do
13
+ fragment = Fragment.new("spec/test-files/fragment4.html", 'spec/test-files')
14
+ result = fragment.to_html
15
+ result.gsub!("\n", '')
16
+ result.should == '<h1>title</h1><p>para</p><p>footer</p>'
17
+ end
18
+
19
+ it "should replace one fragment tag in markdown" do
20
+ fragment = Fragment.new("spec/test-files/fragment3.html", 'spec/test-files')
21
+ fragment.to_html.start_with?('<h1>title</h1>').should be_true
22
+ end
23
+
24
+ it "should replace some fragment tags" do
25
+ fragment = Fragment.new("spec/test-files/fragment2.html", 'spec/test-files')
26
+ result = fragment.to_html.gsub("\n", '')
27
+ result.should == ("<p>abcde</p>")
28
+ end
29
+
30
+ it "should not change a file without fragment tag" do
31
+ fragment = Fragment.new("spec/test-files/nothing.html", 'spec/test-files')
32
+ fragment.to_html.start_with?("<h1>title</h1>").should be_true
33
+ end
34
+
35
+ end
@@ -26,4 +26,14 @@ describe HtmlDocument do
26
26
  tags.size.should == 2
27
27
  end
28
28
 
29
+ it "should build a page content from markdown" do
30
+ content = HtmlDocument.build_page_content("spec/test-files/test.markdown", 'spec/test-files')
31
+ content.should == '<h1>title</h1>'
32
+ end
33
+
34
+ it "should build page content from html" do
35
+ content = HtmlDocument.build_page_content("spec/test-files/fragment.html", 'spec/test-files')
36
+ content.start_with?('<h1>title</h1>').should be_true
37
+ end
38
+
29
39
  end
@@ -29,6 +29,10 @@ describe ProjectCreator do
29
29
  File.exist?('spec/project-name/news').should == true
30
30
  end
31
31
 
32
+ it "should create a fragments folder" do
33
+ File.exist?('spec/project-name/fragments').should == true
34
+ end
35
+
32
36
  it "should create a pages folder" do
33
37
  File.exist?('spec/project-name/pages').should == true
34
38
  end
@@ -0,0 +1 @@
1
+ <genit class="fragment" file="title.html" />
@@ -0,0 +1,7 @@
1
+ <p>
2
+ a
3
+ <genit class="fragment" file="b.html" />
4
+ c
5
+ <genit class="fragment" file="d.html" />
6
+ e
7
+ </p>
@@ -0,0 +1 @@
1
+ <genit class="fragment" file="title.markdown" />
@@ -0,0 +1,5 @@
1
+ <h1>title</h1>
2
+
3
+ <p>para</p>
4
+
5
+ <genit class="fragment" file="footer.html"/>
@@ -0,0 +1 @@
1
+ <p>footer</p>
@@ -0,0 +1 @@
1
+ <h1>title</h1>
@@ -0,0 +1,2 @@
1
+ title
2
+ ======
@@ -0,0 +1 @@
1
+ <h1>title</h1>
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.2'
4
+ version: '0.3'
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-07-02 00:00:00.000000000 +02:00
12
+ date: 2011-07-23 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: &82395440 !ruby/object:Gem::Requirement
17
+ requirement: &75668220 !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: *82395440
25
+ version_requirements: *75668220
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: nokogiri
28
- requirement: &82395100 !ruby/object:Gem::Requirement
28
+ requirement: &75643120 !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: *82395100
36
+ version_requirements: *75643120
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bluecloth
39
- requirement: &82394760 !ruby/object:Gem::Requirement
39
+ requirement: &75642670 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 2.1.0
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *82394760
47
+ version_requirements: *75642670
48
48
  description: ! "Genit builds a **static web site**, that is a web site without server
49
49
  side \nprograming language and database. The site consists only of xhtml code (+
50
50
  css and medias) and \neventually of javascript. It is a command line framework,
@@ -60,9 +60,12 @@ files:
60
60
  - lib/genit/project_creator.rb
61
61
  - lib/genit/html_document.rb
62
62
  - lib/genit/builder.rb
63
+ - lib/genit/file_writer.rb
63
64
  - lib/genit/xml_document.rb
64
65
  - lib/genit/page_compiler.rb
66
+ - lib/genit/fragment.rb
65
67
  - lib/genit/compiler.rb
68
+ - lib/genit/extensions.rb
66
69
  - lib/genit/document_writer.rb
67
70
  - lib/genit.rb
68
71
  - bin/genit
@@ -79,12 +82,24 @@ files:
79
82
  - data/pages/index.html
80
83
  - spec/compiler_spec.rb
81
84
  - spec/builder_spec.rb
85
+ - spec/fragment_spec.rb
82
86
  - spec/helper.rb
83
87
  - spec/html_document_spec.rb
84
88
  - spec/nokogiri_spec.rb
85
89
  - spec/project_creator_spec.rb
90
+ - spec/extensions_spec.rb
86
91
  - spec/bluecloth_spec.rb
92
+ - spec/test-files/fragment4.html
93
+ - spec/test-files/fragment3.html
87
94
  - spec/test-files/test.markdown
95
+ - spec/test-files/fragment2.html
96
+ - spec/test-files/fragment.html
97
+ - spec/test-files/fragments/footer.html
98
+ - spec/test-files/fragments/b.html
99
+ - spec/test-files/fragments/title.html
100
+ - spec/test-files/fragments/title.markdown
101
+ - spec/test-files/fragments/d.html
102
+ - spec/test-files/nothing.html
88
103
  - spec/xml_document_spec.rb
89
104
  - VERSION
90
105
  - NEWS