genit 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS +5 -0
- data/README.markdown +4 -1
- data/TODO +17 -11
- data/VERSION +1 -1
- data/lib/genit.rb +3 -1
- data/lib/genit/compiler.rb +2 -2
- data/lib/genit/document_writer.rb +7 -4
- data/lib/genit/extensions.rb +17 -0
- data/lib/genit/file_writer.rb +16 -0
- data/lib/genit/fragment.rb +49 -0
- data/lib/genit/html_document.rb +35 -5
- data/lib/genit/page_compiler.rb +6 -2
- data/lib/genit/project_creator.rb +1 -1
- data/spec/extensions_spec.rb +35 -0
- data/spec/fragment_spec.rb +35 -0
- data/spec/html_document_spec.rb +10 -0
- data/spec/project_creator_spec.rb +4 -0
- data/spec/test-files/fragment.html +1 -0
- data/spec/test-files/fragment2.html +7 -0
- data/spec/test-files/fragment3.html +1 -0
- data/spec/test-files/fragment4.html +5 -0
- data/spec/test-files/fragments/b.html +1 -0
- data/spec/test-files/fragments/d.html +1 -0
- data/spec/test-files/fragments/footer.html +1 -0
- data/spec/test-files/fragments/title.html +1 -0
- data/spec/test-files/fragments/title.markdown +2 -0
- data/spec/test-files/nothing.html +1 -0
- metadata +23 -8
data/NEWS
CHANGED
data/README.markdown
CHANGED
@@ -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
|
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
|
-
====
|
1
|
+
release v0.3
|
3
2
|
|
4
|
-
release
|
5
3
|
|
6
4
|
|
7
|
-
|
5
|
+
smoke test
|
8
6
|
|
9
|
-
|
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
|
-
|
18
|
+
web site for genit
|
19
|
+
|
20
|
+
announce site (freshmeat et blog)
|
21
|
+
|
22
|
+
news
|
23
|
+
|
24
|
+
release v0.5
|
19
25
|
|
20
|
-
|
26
|
+
Trouver / penser à / un framework de test xhtml/css
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3
|
data/lib/genit.rb
CHANGED
@@ -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
|
data/lib/genit/compiler.rb
CHANGED
@@ -32,13 +32,13 @@ module Genit
|
|
32
32
|
|
33
33
|
def compile_page
|
34
34
|
pc = PageCompiler.new @working_dir, @filename
|
35
|
-
@
|
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 @
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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,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
|
data/lib/genit/html_document.rb
CHANGED
@@ -8,7 +8,9 @@ module Genit
|
|
8
8
|
# Open an html file in various format.
|
9
9
|
class HtmlDocument
|
10
10
|
|
11
|
-
# Public: Open
|
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
|
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
|
-
|
28
|
-
|
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
|
data/lib/genit/page_compiler.rb
CHANGED
@@ -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',
|
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
|
data/spec/html_document_spec.rb
CHANGED
@@ -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 @@
|
|
1
|
+
<genit class="fragment" file="title.markdown" />
|
@@ -0,0 +1 @@
|
|
1
|
+
b
|
@@ -0,0 +1 @@
|
|
1
|
+
d
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>footer</p>
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>title</h1>
|
@@ -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.
|
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-
|
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: &
|
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: *
|
25
|
+
version_requirements: *75668220
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: nokogiri
|
28
|
-
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: *
|
36
|
+
version_requirements: *75643120
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bluecloth
|
39
|
-
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: *
|
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
|