genit 0.4.1 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS +9 -0
- data/TODO +3 -28
- data/VERSION +1 -1
- data/bin/genit +1 -1
- data/lib/genit.rb +8 -0
- data/lib/genit/body_link_builder.rb +35 -0
- data/lib/genit/builder.rb +1 -24
- data/lib/genit/builder_base.rb +46 -0
- data/lib/genit/class_tag.rb +66 -0
- data/lib/genit/compiler.rb +3 -3
- data/lib/genit/document_writer.rb +7 -0
- data/lib/genit/extensions.rb +28 -0
- data/lib/genit/file_writer.rb +8 -0
- data/lib/genit/head_link_builder.rb +32 -0
- data/lib/genit/html_document.rb +1 -1
- data/lib/genit/menu_builder.rb +30 -0
- data/lib/genit/page_compiler.rb +15 -33
- data/lib/genit/tag.rb +36 -0
- data/lib/genit/tag_processor.rb +34 -0
- data/lib/genit/var_tag.rb +44 -0
- data/lib/genit/xml_document.rb +10 -0
- data/spec/builder_base_spec.rb +17 -0
- data/spec/builder_spec.rb +2 -2
- data/spec/compiler_spec.rb +25 -0
- data/spec/file_writer_spec.rb +17 -0
- data/spec/menu_builder_spec.rb +65 -0
- data/spec/page_compiler_spec.rb +35 -0
- data/spec/tag_processor_spec.rb +8 -0
- data/spec/xml_document_spec.rb +5 -0
- metadata +23 -10
data/NEWS
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
v0.5 2011-08-06
|
2
|
+
|
3
|
+
* You can pass string variables from page to template
|
4
|
+
|
5
|
+
* Pages can be organized into subfolders
|
6
|
+
|
7
|
+
* fix a bug where the cli option -v crashed
|
8
|
+
|
9
|
+
|
1
10
|
v0.4.1 2011-07-30
|
2
11
|
|
3
12
|
* Fix a bug where the closing part of auto-closing tags were forgotten.
|
data/TODO
CHANGED
@@ -1,34 +1,9 @@
|
|
1
|
+
dans la doc : tous les liens internes doivent être relatifs au dossier de base (fichier index.html)
|
1
2
|
|
2
|
-
BUGS
|
3
|
-
================
|
4
|
-
#35
|
5
|
-
Les fermetures des balise <meta/> et <link/> sont "oubliées" ?
|
6
|
-
Aïe !!! Il semblerait que ce soit le cas de TOUTES les balises auto-fermantes !
|
7
3
|
|
8
4
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
web site for genit
|
13
|
-
announce site (freshmeat, twitter, et blog)
|
14
|
-
|
15
|
-
|
16
|
-
passer des variables d'une page au template
|
17
|
-
|
18
|
-
pages subfolder (par ex. pour la doc)
|
19
|
-
|
5
|
+
-------------
|
20
6
|
news
|
21
7
|
|
22
8
|
|
23
|
-
|
24
|
-
============
|
25
|
-
Trouver / penser à / un framework de test xhtml/css
|
26
|
-
|
27
|
-
plusieurs templates
|
28
|
-
|
29
|
-
pouvoir changer le title(head) de la page
|
30
|
-
|
31
|
-
fichiers publiques: tout ce qui n'a pas à être 'processer', comme
|
32
|
-
des fichiers texte, pdf, image, vidéo, etc.
|
33
|
-
|
34
|
-
Recommended list of Doctype declarations : http://www.w3.org/QA/2002/04/valid-dtd-list.html
|
9
|
+
-------------
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5
|
data/bin/genit
CHANGED
data/lib/genit.rb
CHANGED
@@ -9,7 +9,15 @@ require 'genit/document_writer'
|
|
9
9
|
require 'genit/compiler'
|
10
10
|
require 'genit/page_compiler'
|
11
11
|
require 'genit/builder'
|
12
|
+
require 'genit/builder_base'
|
13
|
+
require 'genit/menu_builder'
|
14
|
+
require 'genit/head_link_builder'
|
15
|
+
require 'genit/body_link_builder'
|
12
16
|
require 'genit/fragment'
|
17
|
+
require 'genit/tag_processor'
|
18
|
+
require 'genit/tag'
|
19
|
+
require 'genit/var_tag'
|
20
|
+
require 'genit/class_tag'
|
13
21
|
|
14
22
|
module Genit
|
15
23
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Genit
|
6
|
+
|
7
|
+
# Modify links.
|
8
|
+
class BodyLinkBuilder < BuilderBase
|
9
|
+
|
10
|
+
# Public: Build the menu of a particular page.
|
11
|
+
#
|
12
|
+
# page_name - The string filename of the page to build menu for.
|
13
|
+
#
|
14
|
+
# Returns the modified Nokogiri::XML::Document
|
15
|
+
def build_for_page page_name
|
16
|
+
build page_name, get_links
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def get_links
|
22
|
+
@document.css("body a")
|
23
|
+
end
|
24
|
+
|
25
|
+
def update link
|
26
|
+
@path = link['href']
|
27
|
+
return if @path =~ URI::regexp
|
28
|
+
nb = BuilderBase::get_number_of_base_dirs @page_name
|
29
|
+
make_relative nb
|
30
|
+
link['href'] = @path
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/lib/genit/builder.rb
CHANGED
@@ -4,7 +4,7 @@ require 'nokogiri'
|
|
4
4
|
|
5
5
|
module Genit
|
6
6
|
|
7
|
-
# Build a document from various sources.
|
7
|
+
# Build a document, that may be a fragment, from various sources.
|
8
8
|
class Builder
|
9
9
|
|
10
10
|
# Public: Constructor.
|
@@ -31,29 +31,6 @@ module Genit
|
|
31
31
|
@document
|
32
32
|
end
|
33
33
|
|
34
|
-
# Public: Mark the <a> element of the menu that is selected (the displayed
|
35
|
-
# page).
|
36
|
-
#
|
37
|
-
# page_name - The String filename of the page
|
38
|
-
#
|
39
|
-
# Examples
|
40
|
-
#
|
41
|
-
# menu = Nokogiri::XML(File.open('menu.html'))
|
42
|
-
# builder = Builder.new(menu)
|
43
|
-
# menu = builder.select_menu('index.html')
|
44
|
-
#
|
45
|
-
# Return the updated Nokogiri::XML::Document document.
|
46
|
-
def select_menu page_name
|
47
|
-
tags = @document.css("ul#menu a")
|
48
|
-
tags.each {|tag|
|
49
|
-
if tag['href'] == page_name.gsub(/\.markdown$/, '.html')
|
50
|
-
tag['id'] = 'selected'
|
51
|
-
break
|
52
|
-
end
|
53
|
-
}
|
54
|
-
@document
|
55
|
-
end
|
56
|
-
|
57
34
|
end
|
58
35
|
|
59
36
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Genit
|
6
|
+
|
7
|
+
# A base class for all builders.
|
8
|
+
class BuilderBase
|
9
|
+
|
10
|
+
# Public: Constructor.
|
11
|
+
#
|
12
|
+
# doc - A Nokogiri::XML::Document
|
13
|
+
def initialize doc
|
14
|
+
raise RuntimeError if doc.nil?
|
15
|
+
@document = doc
|
16
|
+
end
|
17
|
+
|
18
|
+
# Define me in child
|
19
|
+
def build_for_page page_name
|
20
|
+
raise NotImplementedError
|
21
|
+
end
|
22
|
+
|
23
|
+
def build page_name, elements
|
24
|
+
@page_name = page_name
|
25
|
+
elements.each {|elem| update elem }
|
26
|
+
@document
|
27
|
+
end
|
28
|
+
|
29
|
+
def BuilderBase.get_number_of_base_dirs filename
|
30
|
+
return 0 if filename =~ URI::regexp
|
31
|
+
|
32
|
+
dirs = File.dirname filename
|
33
|
+
return 0 if dirs == '.'
|
34
|
+
|
35
|
+
return dirs.split('/').size
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def make_relative nb
|
41
|
+
nb.times { @path = '../' + @path }
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,66 @@
|
|
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
|
data/lib/genit/compiler.rb
CHANGED
@@ -35,9 +35,9 @@ module Genit
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def compile_pages
|
38
|
-
Dir.
|
39
|
-
next if
|
40
|
-
@filename = file
|
38
|
+
Dir.glob(File.join(@working_dir, 'pages', '**/*')) do |file|
|
39
|
+
next if File.directory?(file)
|
40
|
+
@filename = file.gsub(File.join(@working_dir, 'pages') + '/', '')
|
41
41
|
compile_page
|
42
42
|
end
|
43
43
|
end
|
@@ -19,11 +19,18 @@ 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_xhtml document, filename
|
22
|
+
@document = document
|
23
|
+
remove_remaining_tags
|
22
24
|
FileWriter.write document.to_xhtml, get_full_path(filename.force_html_extension)
|
23
25
|
end
|
24
26
|
|
25
27
|
private
|
26
28
|
|
29
|
+
def remove_remaining_tags
|
30
|
+
tags = @document.css 'genit'
|
31
|
+
tags.each {|tag| tag.remove}
|
32
|
+
end
|
33
|
+
|
27
34
|
def get_full_path filename
|
28
35
|
File.join(@working_dir, 'www', filename)
|
29
36
|
end
|
data/lib/genit/extensions.rb
CHANGED
@@ -15,3 +15,31 @@ class String
|
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
18
|
+
|
19
|
+
module Nokogiri
|
20
|
+
module XML
|
21
|
+
|
22
|
+
# I think it's a bad idea to extend the Nokogiri library cause it makes a
|
23
|
+
# too big dependency on Genit.
|
24
|
+
# It will be much better to do a little wrapper over Nokogiri::XML::Node.
|
25
|
+
class Node
|
26
|
+
|
27
|
+
def genit_class?
|
28
|
+
if self['class']
|
29
|
+
true
|
30
|
+
else
|
31
|
+
false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def genit_var?
|
36
|
+
if self['var']
|
37
|
+
true
|
38
|
+
else
|
39
|
+
false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/genit/file_writer.rb
CHANGED
@@ -8,9 +8,17 @@ module Genit
|
|
8
8
|
class FileWriter
|
9
9
|
|
10
10
|
def self.write content, full_path
|
11
|
+
create_dirs full_path
|
11
12
|
File.open(full_path, "w") {|out| out.puts content }
|
12
13
|
end
|
13
14
|
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.create_dirs full_path
|
18
|
+
dir = File.dirname full_path
|
19
|
+
FileUtils.makedirs(dir) unless File.directory?(dir)
|
20
|
+
end
|
21
|
+
|
14
22
|
end
|
15
23
|
|
16
24
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Genit
|
4
|
+
|
5
|
+
# Modify head link tags.
|
6
|
+
class HeadLinkBuilder < BuilderBase
|
7
|
+
|
8
|
+
# Public: Build the document head link tags of a particular page.
|
9
|
+
#
|
10
|
+
# page_name - The string filename of the page.
|
11
|
+
#
|
12
|
+
# Returns the modified Nokogiri::XML::Document
|
13
|
+
def build_for_page page_name
|
14
|
+
build page_name, head_links
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def head_links
|
20
|
+
@document.css("head link")
|
21
|
+
end
|
22
|
+
|
23
|
+
def update link
|
24
|
+
@path = link['href']
|
25
|
+
nb = BuilderBase::get_number_of_base_dirs @page_name
|
26
|
+
make_relative nb
|
27
|
+
link['href'] = @path
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/lib/genit/html_document.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Genit
|
4
|
+
|
5
|
+
# Modify menu links.
|
6
|
+
class MenuBuilder < BuilderBase
|
7
|
+
|
8
|
+
# Public: Build the menu of a particular page.
|
9
|
+
#
|
10
|
+
# page_name - The string filename of the page to build menu for.
|
11
|
+
#
|
12
|
+
# Returns the modified Nokogiri::XML::Document
|
13
|
+
def build_for_page page_name
|
14
|
+
build page_name, menu_links
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def menu_links
|
20
|
+
@document.css("ul#menu a")
|
21
|
+
end
|
22
|
+
|
23
|
+
def update link
|
24
|
+
@path = link['href']
|
25
|
+
link['id'] = 'selected' if @path == @page_name.force_html_extension
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/genit/page_compiler.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
3
|
module Genit
|
6
4
|
|
7
5
|
# Compile a single page.
|
@@ -19,47 +17,31 @@ module Genit
|
|
19
17
|
|
20
18
|
# Public: Compile the page.
|
21
19
|
#
|
22
|
-
# Returns a Nokogiri::
|
20
|
+
# Returns a Nokogiri::XML document.
|
23
21
|
def compile
|
24
|
-
|
25
|
-
|
26
|
-
@template
|
22
|
+
compile_body
|
23
|
+
compile_head
|
27
24
|
end
|
28
25
|
|
29
26
|
private
|
30
27
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
def compile_body
|
29
|
+
genit_tags_in_template.each do |tag|
|
30
|
+
tp = TagProcessor.new(@working_dir, @template, @filename, tag)
|
31
|
+
@template = tp.process
|
35
32
|
end
|
33
|
+
builder = BodyLinkBuilder.new @template
|
34
|
+
@template = builder.build_for_page @filename
|
36
35
|
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
builder
|
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
|
47
|
-
end
|
48
|
-
|
49
|
-
def tag_menu
|
50
|
-
build_menu
|
51
|
-
replace_menu_into_template
|
52
|
-
end
|
53
|
-
|
54
|
-
def build_menu
|
55
|
-
menu = XmlDocument.open(File.join(@working_dir, "templates/menu.html"))
|
56
|
-
builder = Builder.new(menu)
|
57
|
-
@menu = builder.select_menu(@filename)
|
37
|
+
def compile_head
|
38
|
+
builder = HeadLinkBuilder.new @template
|
39
|
+
builder.build_for_page @filename
|
58
40
|
end
|
59
41
|
|
60
|
-
|
61
|
-
|
62
|
-
|
42
|
+
# Returns all <genit> tags found in the template.
|
43
|
+
def genit_tags_in_template
|
44
|
+
HtmlDocument.genit_tags_from @template
|
63
45
|
end
|
64
46
|
|
65
47
|
end
|
data/lib/genit/tag.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Genit
|
4
|
+
|
5
|
+
# Base class for all Tags.
|
6
|
+
class Tag
|
7
|
+
|
8
|
+
# Public: Constructor.
|
9
|
+
#
|
10
|
+
# working_dir - The String working directory, where live the project.
|
11
|
+
# template - The Nokogiri::XML::Document into which we process the tag.
|
12
|
+
# filename - The String name of the page
|
13
|
+
# tag - The tag to process as a Nokogiri::XML::Element
|
14
|
+
def initialize working_dir, template, filename, tag
|
15
|
+
@working_dir = working_dir
|
16
|
+
@filename = filename
|
17
|
+
@template = template
|
18
|
+
@tag = tag
|
19
|
+
end
|
20
|
+
|
21
|
+
# Public: Replace a tag by a string content into the template.
|
22
|
+
# This method not only returns the modified template, it also really replace
|
23
|
+
# the template in place.
|
24
|
+
#
|
25
|
+
# css_rule - The String css rule to identify the tag to replace.
|
26
|
+
# string - The String replacement.
|
27
|
+
#
|
28
|
+
# Returns the template as a Nokogiri::XML::Document
|
29
|
+
def replace_tag_into_template! css_rule, string
|
30
|
+
builder = Builder.new(@template)
|
31
|
+
@template = builder.replace(css_rule, string)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Genit
|
4
|
+
|
5
|
+
# Replace a tag in a template.
|
6
|
+
class TagProcessor
|
7
|
+
|
8
|
+
# Public: Constructor.
|
9
|
+
#
|
10
|
+
# working_dir - The String working directory, where live the project.
|
11
|
+
# template - The Nokogiri::XML::Document into which we process the tag.
|
12
|
+
# filename - The String name of the page
|
13
|
+
# tag - The tag to process as a Nokogiri::XML::Element
|
14
|
+
def initialize working_dir, template, filename, tag
|
15
|
+
@working_dir = working_dir
|
16
|
+
@filename = filename
|
17
|
+
@template = template
|
18
|
+
if tag.genit_class?
|
19
|
+
@tag = ClassTag.new(@working_dir, @template, @filename, tag)
|
20
|
+
elsif tag.genit_var?
|
21
|
+
@tag = VarTag.new(@working_dir, @template, @filename, tag)
|
22
|
+
else
|
23
|
+
raise RuntimeError
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the modified template as a Nokogiri::XML::Document
|
28
|
+
def process
|
29
|
+
@tag.process
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Genit
|
4
|
+
|
5
|
+
# A Genit tag that represents a variable.
|
6
|
+
# For example, in the template you have: <genit var="page_title"/>,
|
7
|
+
# and in the page you have: <genit var="page_title">My Title</genit>.
|
8
|
+
class VarTag < Tag
|
9
|
+
|
10
|
+
# Public: Constructor.
|
11
|
+
#
|
12
|
+
# working_dir - The String working directory, where live the project.
|
13
|
+
# template - The Nokogiri::XML::Document into which we process the tag.
|
14
|
+
# filename - The String name of the page
|
15
|
+
# tag - The tag to process as a Nokogiri::XML::Element
|
16
|
+
def initialize working_dir, template, filename, tag
|
17
|
+
super working_dir, template, filename, tag
|
18
|
+
end
|
19
|
+
|
20
|
+
# Public: Replace a variable in the template. The variable content is found
|
21
|
+
# in the tag in the page.
|
22
|
+
#
|
23
|
+
# Returns the template as a Nokogiri::XML::Document
|
24
|
+
def process
|
25
|
+
replace_tag_into_template! get_css_rule, get_variable_value
|
26
|
+
@template
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def get_css_rule
|
32
|
+
var_name = @tag['var']
|
33
|
+
"genit[var='#{var_name}']"
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_variable_value
|
37
|
+
filename = File.join(@working_dir, 'pages', @filename)
|
38
|
+
doc = HtmlDocument.open filename
|
39
|
+
doc.at_css("genit[var='#{@tag['var']}']").inner_html
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/lib/genit/xml_document.rb
CHANGED
@@ -17,6 +17,16 @@ module Genit
|
|
17
17
|
Nokogiri::XML(File.open(file))
|
18
18
|
end
|
19
19
|
|
20
|
+
# Public: Open a fragment of xml document.
|
21
|
+
#
|
22
|
+
# file - Full path String filename.
|
23
|
+
#
|
24
|
+
# Returns a Nokogiri::XML document.
|
25
|
+
def self.open_fragment file
|
26
|
+
string = IO.read file
|
27
|
+
Nokogiri::XML.fragment string
|
28
|
+
end
|
29
|
+
|
20
30
|
end
|
21
31
|
|
22
32
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require './spec/helper'
|
4
|
+
|
5
|
+
describe BuilderBase do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
test_file = %q{<body></body>}
|
9
|
+
@doc = Nokogiri::XML.fragment test_file
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should not be instanciated" do
|
13
|
+
builder = BuilderBase.new(@doc)
|
14
|
+
lambda {builder.build_for_page('index.html')}.should raise_error(NotImplementedError)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/spec/builder_spec.rb
CHANGED
@@ -16,8 +16,8 @@ describe Builder do
|
|
16
16
|
|
17
17
|
it "should set the menu" do
|
18
18
|
menu = Nokogiri::XML(File.open("data/templates/menu.html"))
|
19
|
-
builder =
|
20
|
-
menu = builder.
|
19
|
+
builder = MenuBuilder.new(menu)
|
20
|
+
menu = builder.build_for_page('index.html')
|
21
21
|
menu.css("ul#menu a#selected").size.should == 1
|
22
22
|
menu.css("ul#menu a#selected").first['href'].should == 'index.html'
|
23
23
|
end
|
data/spec/compiler_spec.rb
CHANGED
@@ -48,4 +48,29 @@ 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
|
74
|
+
end
|
75
|
+
|
51
76
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require './spec/helper'
|
4
|
+
|
5
|
+
describe FileWriter do
|
6
|
+
|
7
|
+
after :all do
|
8
|
+
clean_test_repository
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should create dirs if they doesn't exist" do
|
12
|
+
test_file = 'spec/project-name/dir1/dir2/test.file'
|
13
|
+
FileWriter.write 'content', test_file
|
14
|
+
File.exists?(test_file).should == true
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require './spec/helper'
|
4
|
+
|
5
|
+
describe MenuBuilder do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
menu_test = %q{
|
9
|
+
<ul id="menu">
|
10
|
+
<li><a href="index.html">home</a></li>
|
11
|
+
<li><a href="about.html">about</a></li>
|
12
|
+
<li><a href="doc/index.html">doc</a></li>
|
13
|
+
<li><a href="doc/a.html">doca</a></li>
|
14
|
+
<li><a href="doc/b.html">docb</a></li>
|
15
|
+
<li><a href="a/b/c1.html">abc1</a></li>
|
16
|
+
<li><a href="a/b/c2.html">abc2</a></li>
|
17
|
+
<li><a href="/absolute.html">absolute</a></li>
|
18
|
+
<li><a href="http://www.truc.com/file.html">file</a></li>
|
19
|
+
</ul>}
|
20
|
+
@menu_doc = Nokogiri::XML.fragment menu_test
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should set the menu for index.html page" do
|
24
|
+
builder = MenuBuilder.new(@menu_doc)
|
25
|
+
new_menu = builder.build_for_page('index.html')
|
26
|
+
new_menu.css("ul#menu a#selected").size.should == 1
|
27
|
+
new_menu.css("ul#menu a#selected").first['href'].should == 'index.html'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should set the menu for about.html page" do
|
31
|
+
builder = MenuBuilder.new(@menu_doc)
|
32
|
+
new_menu = builder.build_for_page('about.html')
|
33
|
+
new_menu.css("ul#menu a#selected").size.should == 1
|
34
|
+
new_menu.css("ul#menu a#selected").first['href'].should == 'about.html'
|
35
|
+
end
|
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
|
+
it "should set the menu for /absolute.html page" do
|
52
|
+
builder = MenuBuilder.new(@menu_doc)
|
53
|
+
new_menu = builder.build_for_page('/absolute.html')
|
54
|
+
new_menu.css("ul#menu a#selected").size.should == 1
|
55
|
+
new_menu.css("ul#menu a#selected").first['href'].should == '/absolute.html'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should set the menu for http://www.truc.com/file.html page" do
|
59
|
+
builder = MenuBuilder.new(@menu_doc)
|
60
|
+
new_menu = builder.build_for_page('http://www.truc.com/file.html')
|
61
|
+
new_menu.css("ul#menu a#selected").size.should == 1
|
62
|
+
new_menu.css("ul#menu a#selected").first['href'].should == 'http://www.truc.com/file.html'
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require './spec/helper'
|
4
|
+
|
5
|
+
describe PageCompiler do
|
6
|
+
|
7
|
+
after :all do
|
8
|
+
clean_test_repository
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_sample_project
|
12
|
+
FileUtils.makedirs('spec/project-name/templates')
|
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>' }
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should substitute a variable" do
|
19
|
+
create_sample_project
|
20
|
+
pc = PageCompiler.new 'spec/project-name/', 'index.html'
|
21
|
+
doc = pc.compile
|
22
|
+
|
23
|
+
doc.at_css('h1').inner_html.should == 'My Title'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not delete the tag from page when a var is subsituted" do
|
27
|
+
create_sample_project
|
28
|
+
pc = PageCompiler.new 'spec/project-name/', 'index.html'
|
29
|
+
doc = pc.compile
|
30
|
+
|
31
|
+
page = IO.read 'spec/project-name/pages/index.html'
|
32
|
+
page.match('<genit var="title">My Title</genit>').should_not == nil
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/spec/xml_document_spec.rb
CHANGED
@@ -8,5 +8,10 @@ describe XmlDocument do
|
|
8
8
|
doc = XmlDocument.open("data/templates/menu.html")
|
9
9
|
doc.css("ul#menu li").size.should >= 1
|
10
10
|
end
|
11
|
+
|
12
|
+
it "should load as a fragment" do
|
13
|
+
doc = XmlDocument.open_fragment("data/templates/menu.html")
|
14
|
+
doc.css("ul#menu li").size.should >= 1
|
15
|
+
end
|
11
16
|
|
12
17
|
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.
|
4
|
+
version: '0.5'
|
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-
|
12
|
+
date: 2011-08-06 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: &72437520 !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: *72437520
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: nokogiri
|
28
|
-
requirement: &
|
28
|
+
requirement: &72437120 !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: *72437120
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bluecloth
|
39
|
-
requirement: &
|
39
|
+
requirement: &72436670 !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: *
|
47
|
+
version_requirements: *72436670
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: clamp
|
50
|
-
requirement: &
|
50
|
+
requirement: &72436180 !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: *
|
58
|
+
version_requirements: *72436180
|
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,13 +68,21 @@ executables:
|
|
68
68
|
extensions: []
|
69
69
|
extra_rdoc_files: []
|
70
70
|
files:
|
71
|
+
- lib/genit/head_link_builder.rb
|
71
72
|
- lib/genit/project_creator.rb
|
73
|
+
- lib/genit/var_tag.rb
|
72
74
|
- lib/genit/html_document.rb
|
73
75
|
- lib/genit/builder.rb
|
74
76
|
- lib/genit/file_writer.rb
|
75
77
|
- lib/genit/xml_document.rb
|
78
|
+
- lib/genit/menu_builder.rb
|
79
|
+
- lib/genit/tag_processor.rb
|
80
|
+
- lib/genit/builder_base.rb
|
76
81
|
- lib/genit/page_compiler.rb
|
77
82
|
- lib/genit/fragment.rb
|
83
|
+
- lib/genit/tag.rb
|
84
|
+
- lib/genit/body_link_builder.rb
|
85
|
+
- lib/genit/class_tag.rb
|
78
86
|
- lib/genit/compiler.rb
|
79
87
|
- lib/genit/extensions.rb
|
80
88
|
- lib/genit/document_writer.rb
|
@@ -91,11 +99,15 @@ files:
|
|
91
99
|
- data/styles/yui/base.css
|
92
100
|
- data/styles/yui/fonts.css
|
93
101
|
- data/pages/index.html
|
102
|
+
- spec/file_writer_spec.rb
|
94
103
|
- spec/compiler_spec.rb
|
104
|
+
- spec/tag_processor_spec.rb
|
95
105
|
- spec/builder_spec.rb
|
96
106
|
- spec/fragment_spec.rb
|
107
|
+
- spec/menu_builder_spec.rb
|
97
108
|
- spec/helper.rb
|
98
109
|
- spec/html_document_spec.rb
|
110
|
+
- spec/builder_base_spec.rb
|
99
111
|
- spec/nokogiri_spec.rb
|
100
112
|
- spec/project_creator_spec.rb
|
101
113
|
- spec/extensions_spec.rb
|
@@ -111,6 +123,7 @@ files:
|
|
111
123
|
- spec/test-files/fragments/title.markdown
|
112
124
|
- spec/test-files/fragments/d.html
|
113
125
|
- spec/test-files/nothing.html
|
126
|
+
- spec/page_compiler_spec.rb
|
114
127
|
- spec/xml_document_spec.rb
|
115
128
|
- VERSION
|
116
129
|
- NEWS
|