genit 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS +7 -0
- data/README.markdown +7 -1
- data/Rakefile +12 -4
- data/TODO +12 -3
- data/VERSION +1 -1
- data/data/styles/alsa/all.css +130 -0
- data/data/styles/handheld.css +1 -0
- data/data/styles/print.css +1 -0
- data/data/styles/screen.css +1 -0
- data/data/styles/yui/all.css +3 -0
- data/data/styles/yui/base.css +80 -0
- data/data/styles/yui/fonts.css +47 -0
- data/data/styles/yui/reset.css +126 -0
- data/data/templates/main.html +4 -0
- data/data/templates/menu.html +5 -0
- data/lib/genit.rb +3 -0
- data/lib/genit/builder.rb +25 -2
- data/lib/genit/compiler.rb +19 -23
- data/lib/genit/document_writer.rb +30 -0
- data/lib/genit/html_document.rb +12 -3
- data/lib/genit/page_compiler.rb +63 -0
- data/lib/genit/project_creator.rb +5 -2
- data/lib/genit/xml_document.rb +22 -0
- data/spec/builder_spec.rb +8 -0
- data/spec/compiler_spec.rb +10 -0
- data/spec/html_document_spec.rb +6 -0
- data/spec/nokogiri_spec.rb +8 -5
- data/spec/project_creator_spec.rb +87 -11
- data/spec/xml_document_spec.rb +12 -0
- metadata +21 -8
data/NEWS
CHANGED
data/README.markdown
CHANGED
@@ -54,8 +54,9 @@ for more information.
|
|
54
54
|
Dependencies
|
55
55
|
--------------------------
|
56
56
|
|
57
|
+
### Users dependencies
|
58
|
+
|
57
59
|
* ruby >= 1.9.2
|
58
|
-
|
59
60
|
* nokogiri (xml parser)
|
60
61
|
* bluecloth (markdown parser)
|
61
62
|
|
@@ -65,6 +66,11 @@ Dependencies
|
|
65
66
|
* [coco](https://github.com/lkdjiin/coco) (code coverage must be 90% minimum)
|
66
67
|
* [tomdoc](http://tomdoc.org/) to document your code
|
67
68
|
|
69
|
+
_recommended_
|
70
|
+
|
71
|
+
* reek, to check for code smells
|
72
|
+
* flay, to check for duplicated code
|
73
|
+
|
68
74
|
|
69
75
|
License
|
70
76
|
--------------------------
|
data/Rakefile
CHANGED
@@ -3,6 +3,11 @@
|
|
3
3
|
require 'rake'
|
4
4
|
require 'rspec/core/rake_task'
|
5
5
|
|
6
|
+
def ruby_files_for_shell
|
7
|
+
files = Dir.glob 'lib/**/*.rb'
|
8
|
+
files.join(' ')
|
9
|
+
end
|
10
|
+
|
6
11
|
desc 'Test genit'
|
7
12
|
task :default => :spec
|
8
13
|
|
@@ -14,10 +19,13 @@ end
|
|
14
19
|
desc 'Check for code smells'
|
15
20
|
task :reek do
|
16
21
|
puts 'Checking for code smells...'
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
sh "reek --quiet #{ruby_files_for_shell} | ./reek.sed"
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Check for duplicate code'
|
26
|
+
task :flay do
|
27
|
+
puts 'Check for duplicate code...'
|
28
|
+
exec "flay #{ruby_files_for_shell}"
|
21
29
|
end
|
22
30
|
|
23
31
|
desc 'Build genit & install it'
|
data/TODO
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2
|
@@ -0,0 +1,130 @@
|
|
1
|
+
/* --- STYLES DE BASE ---
|
2
|
+
*
|
3
|
+
* from alsacréations:
|
4
|
+
* http://www.alsacreations.com/astuce/lire/654-feuille-de-styles-de-base.html
|
5
|
+
*/
|
6
|
+
|
7
|
+
/* Page */
|
8
|
+
html {
|
9
|
+
font-size: 100%; /* Évite un bug d'IE 6-7. (1) */
|
10
|
+
}
|
11
|
+
body {
|
12
|
+
margin: 0;
|
13
|
+
padding: 1em; /* Remettre à zéro si nécessaire. */
|
14
|
+
/* Pensez à utiliser une collection de polices (2), par ex:
|
15
|
+
font-family: Arial, Helvetica, FreeSans, sans-serif; */
|
16
|
+
font-size: .8em; /* À adapter pour la police choisie. (3) */
|
17
|
+
line-height: 1.4; /* À adapter au design. (4) */
|
18
|
+
color: black;
|
19
|
+
background: white;
|
20
|
+
}
|
21
|
+
|
22
|
+
/* Titres */
|
23
|
+
h1, h2, h3, h4, h5, h6 {
|
24
|
+
margin: 1em 0 .5em 0; /* Rapproche le titre du texte. (5) */
|
25
|
+
line-height: 1.2;
|
26
|
+
font-weight: bold; /* Valeur par défaut. (6) */
|
27
|
+
font-style: normal;
|
28
|
+
}
|
29
|
+
h1 {
|
30
|
+
font-size: 1.75em;
|
31
|
+
}
|
32
|
+
h2 {
|
33
|
+
font-size: 1.5em;
|
34
|
+
}
|
35
|
+
h3 {
|
36
|
+
font-size: 1.25em;
|
37
|
+
}
|
38
|
+
h4 {
|
39
|
+
font-size: 1em;
|
40
|
+
}
|
41
|
+
|
42
|
+
/* Listes */
|
43
|
+
ul, ol {
|
44
|
+
margin: .75em 0 .75em 32px;
|
45
|
+
padding: 0;
|
46
|
+
}
|
47
|
+
|
48
|
+
/* Paragraphes */
|
49
|
+
p {
|
50
|
+
margin: .75em 0; /* Marges plus faibles que par défaut. (7) */
|
51
|
+
}
|
52
|
+
address {
|
53
|
+
margin: .75em 0;
|
54
|
+
font-style: normal;
|
55
|
+
}
|
56
|
+
|
57
|
+
/* Liens */
|
58
|
+
a {
|
59
|
+
text-decoration: underline;
|
60
|
+
}
|
61
|
+
a:link {
|
62
|
+
color: #11C;
|
63
|
+
}
|
64
|
+
a:visited {
|
65
|
+
color: #339;
|
66
|
+
}
|
67
|
+
a:hover, a:focus, a:active {
|
68
|
+
color: #00F;
|
69
|
+
}
|
70
|
+
|
71
|
+
/* Pas de bordure autour des images dans les liens */
|
72
|
+
a img {
|
73
|
+
border: none;
|
74
|
+
}
|
75
|
+
|
76
|
+
/* Divers éléments de type en-ligne (8) */
|
77
|
+
em {
|
78
|
+
font-style: italic;
|
79
|
+
}
|
80
|
+
strong {
|
81
|
+
font-weight: bold;
|
82
|
+
}
|
83
|
+
|
84
|
+
/* Formulaires */
|
85
|
+
form, fieldset {
|
86
|
+
margin: 0;
|
87
|
+
padding: 0;
|
88
|
+
border: none;
|
89
|
+
}
|
90
|
+
input, button, select {
|
91
|
+
vertical-align: middle; /* Solution pb. d'alignement. (9) */
|
92
|
+
}
|
93
|
+
|
94
|
+
/*
|
95
|
+
* 1. Bug décrit sur la page suivante: Bug avec l’unité relative em et Internet Explorer.
|
96
|
+
*
|
97
|
+
* 2. Pour un choix de collections de polices (font-family, voir Quelles polices de caractères
|
98
|
+
* (fontes) utiliser sur le Web?.
|
99
|
+
*
|
100
|
+
* 3. Ici, on utilise les styles de l'élément body pour définir la taille du texte globale pour le
|
101
|
+
* site. Une police Arial ou Helvetica à .8em, soit 80% de la taille du texte par défaut du
|
102
|
+
* navigateur, fournit une bonne lisibilité. Il faudra adapter cette valeur suivant la police
|
103
|
+
* choisie, les besoins du design, etc.
|
104
|
+
*
|
105
|
+
* 4. Les valeurs 1.1 et 1.2 conviennent marchent bien pour les titres, voire pour le texte dans des
|
106
|
+
* colonnes étroites. Pour des lignes de texte plus longues, on utilisera plutôt des valeurs
|
107
|
+
* entre 1.2 (120%) et 1.8 (180%).
|
108
|
+
*
|
109
|
+
* 5. Avec les styles par défaut des navigateurs, les titres ont souvent une marge supérieure et une
|
110
|
+
* marge inférieure égales. Du coup, on ne reconnait pas au premier coup d'œil que le titre se
|
111
|
+
* rapporte au texte qui le suit. Le style proposé corrige ce défaut. Pour retrouver le style par
|
112
|
+
* défaut des navigateurs, utilisez un margin: 1em 0;.
|
113
|
+
*
|
114
|
+
* 6. Dans les styles par défaut des navigateurs, les titres sont en gras. Si vous souhaitez une
|
115
|
+
* graisse normale pour la plupart de vos titres, utilisez plutôt font-weight: normal.
|
116
|
+
*
|
117
|
+
* 7. On utilise des em afin que les marges des paragraphes soient proportionnelles à la taille du
|
118
|
+
* texte, ce que ne font pas tous les navigateurs (notamment IE). On utilise une valeur de .75em,
|
119
|
+
* soit des retraits entre les paragraphes un peu plus faibles que ceux utilisés par défaut par
|
120
|
+
* les navigateurs. À modifier selon vos besoins.
|
121
|
+
*
|
122
|
+
* 8. Ces styles correspondent aux valeurs par défaut des navigateurs, mais vous voudrez peut-être
|
123
|
+
* les modifier pour votre projet.
|
124
|
+
*
|
125
|
+
* 9. Les éléments de formulaires sont assez difficiles à mettre en forme et à positionner. De plus,
|
126
|
+
* l'alignement vertical des boutons, cases à cocher et autres listes déroulantes est parfois
|
127
|
+
* difficile à gérer. Vu les différences de comportement entre navigateurs, il n'y a pas de
|
128
|
+
* solution parfaite, mais utiliser un alignement vertical centré dans la hauteur de ligne permet
|
129
|
+
* d'avoir un rendu décent avec tous les navigateurs.
|
130
|
+
*/
|
@@ -0,0 +1 @@
|
|
1
|
+
/* Write your rules */
|
@@ -0,0 +1 @@
|
|
1
|
+
/* Write your rules */
|
@@ -0,0 +1 @@
|
|
1
|
+
/* Write your rules */
|
@@ -0,0 +1,80 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
|
3
|
+
Code licensed under the BSD License:
|
4
|
+
http://developer.yahoo.com/yui/license.html
|
5
|
+
version: 3.3.0
|
6
|
+
build: 3167
|
7
|
+
*/
|
8
|
+
/* base.css, part of YUI's CSS Foundation */
|
9
|
+
h1 {
|
10
|
+
/*18px via YUI Fonts CSS foundation*/
|
11
|
+
font-size:138.5%;
|
12
|
+
}
|
13
|
+
h2 {
|
14
|
+
/*16px via YUI Fonts CSS foundation*/
|
15
|
+
font-size:123.1%;
|
16
|
+
}
|
17
|
+
h3 {
|
18
|
+
/*14px via YUI Fonts CSS foundation*/
|
19
|
+
font-size:108%;
|
20
|
+
}
|
21
|
+
h1,h2,h3 {
|
22
|
+
/* top & bottom margin based on font size */
|
23
|
+
margin:1em 0;
|
24
|
+
}
|
25
|
+
h1,h2,h3,h4,h5,h6,strong {
|
26
|
+
/*bringing boldness back to headers and the strong element*/
|
27
|
+
font-weight:bold;
|
28
|
+
}
|
29
|
+
abbr,acronym {
|
30
|
+
/*indicating to users that more info is available */
|
31
|
+
border-bottom:1px dotted #000;
|
32
|
+
cursor:help;
|
33
|
+
}
|
34
|
+
em {
|
35
|
+
/*bringing italics back to the em element*/
|
36
|
+
font-style:italic;
|
37
|
+
}
|
38
|
+
blockquote,ul,ol,dl {
|
39
|
+
/*giving blockquotes and lists room to breath*/
|
40
|
+
margin:1em;
|
41
|
+
}
|
42
|
+
ol,ul,dl {
|
43
|
+
/*bringing lists on to the page with breathing room */
|
44
|
+
margin-left:2em;
|
45
|
+
}
|
46
|
+
ol li {
|
47
|
+
/*giving OL's LIs generated numbers*/
|
48
|
+
list-style: decimal outside;
|
49
|
+
}
|
50
|
+
ul li {
|
51
|
+
/*giving UL's LIs generated disc markers*/
|
52
|
+
list-style: disc outside;
|
53
|
+
}
|
54
|
+
dl dd {
|
55
|
+
/*providing spacing for definition terms*/
|
56
|
+
margin-left:1em;
|
57
|
+
}
|
58
|
+
th,td {
|
59
|
+
/*borders and padding to make the table readable*/
|
60
|
+
border:1px solid #000;
|
61
|
+
padding:.5em;
|
62
|
+
}
|
63
|
+
th {
|
64
|
+
/*distinguishing table headers from data cells*/
|
65
|
+
font-weight:bold;
|
66
|
+
text-align:center;
|
67
|
+
}
|
68
|
+
caption {
|
69
|
+
/*coordinated margin to match cell's padding*/
|
70
|
+
margin-bottom:.5em;
|
71
|
+
/*centered so it doesn't blend in to other content*/
|
72
|
+
text-align:center;
|
73
|
+
}
|
74
|
+
p,fieldset,table,pre {
|
75
|
+
/*so things don't run into each other*/
|
76
|
+
margin-bottom:1em;
|
77
|
+
}
|
78
|
+
/* setting a consistent width, 160px;
|
79
|
+
control of type=file still not possible */
|
80
|
+
input[type=text],input[type=password],textarea{width:12.25em;*width:11.9em;}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
|
3
|
+
Code licensed under the BSD License:
|
4
|
+
http://developer.yahoo.com/yui/license.html
|
5
|
+
version: 3.3.0
|
6
|
+
build: 3167
|
7
|
+
*/
|
8
|
+
/**
|
9
|
+
* Percents could work for IE, but for backCompat purposes, we are using keywords.
|
10
|
+
* x-small is for IE6/7 quirks mode.
|
11
|
+
*/
|
12
|
+
body {
|
13
|
+
font:13px/1.231 arial,helvetica,clean,sans-serif;
|
14
|
+
*font-size:small; /* for IE */
|
15
|
+
*font:x-small; /* for IE in quirks mode */
|
16
|
+
}
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Nudge down to get to 13px equivalent for these form elements
|
20
|
+
*/
|
21
|
+
select,
|
22
|
+
input,
|
23
|
+
button,
|
24
|
+
textarea {
|
25
|
+
font:99% arial,helvetica,clean,sans-serif;
|
26
|
+
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* To help tables remember to inherit
|
30
|
+
*/
|
31
|
+
table {
|
32
|
+
font-size:inherit;
|
33
|
+
font:100%;
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Bump up IE to get to 13px equivalent for these fixed-width elements
|
38
|
+
*/
|
39
|
+
pre,
|
40
|
+
code,
|
41
|
+
kbd,
|
42
|
+
samp,
|
43
|
+
tt {
|
44
|
+
font-family:monospace;
|
45
|
+
*font-size:108%;
|
46
|
+
line-height:100%;
|
47
|
+
}
|
@@ -0,0 +1,126 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
|
3
|
+
Code licensed under the BSD License:
|
4
|
+
http://developer.yahoo.com/yui/license.html
|
5
|
+
version: 3.3.0
|
6
|
+
build: 3167
|
7
|
+
*/
|
8
|
+
/*
|
9
|
+
TODO will need to remove settings on HTML since we can't namespace it.
|
10
|
+
TODO with the prefix, should I group by selector or property for weight savings?
|
11
|
+
*/
|
12
|
+
html{
|
13
|
+
color:#000;
|
14
|
+
background:#FFF;
|
15
|
+
}
|
16
|
+
/*
|
17
|
+
TODO remove settings on BODY since we can't namespace it.
|
18
|
+
*/
|
19
|
+
/*
|
20
|
+
TODO test putting a class on HEAD.
|
21
|
+
- Fails on FF.
|
22
|
+
*/
|
23
|
+
body,
|
24
|
+
div,
|
25
|
+
dl,
|
26
|
+
dt,
|
27
|
+
dd,
|
28
|
+
ul,
|
29
|
+
ol,
|
30
|
+
li,
|
31
|
+
h1,
|
32
|
+
h2,
|
33
|
+
h3,
|
34
|
+
h4,
|
35
|
+
h5,
|
36
|
+
h6,
|
37
|
+
pre,
|
38
|
+
code,
|
39
|
+
form,
|
40
|
+
fieldset,
|
41
|
+
legend,
|
42
|
+
input,
|
43
|
+
textarea,
|
44
|
+
p,
|
45
|
+
blockquote,
|
46
|
+
th,
|
47
|
+
td {
|
48
|
+
margin:0;
|
49
|
+
padding:0;
|
50
|
+
}
|
51
|
+
table {
|
52
|
+
border-collapse:collapse;
|
53
|
+
border-spacing:0;
|
54
|
+
}
|
55
|
+
fieldset,
|
56
|
+
img {
|
57
|
+
border:0;
|
58
|
+
}
|
59
|
+
/*
|
60
|
+
TODO think about hanlding inheritence differently, maybe letting IE6 fail a bit...
|
61
|
+
*/
|
62
|
+
address,
|
63
|
+
caption,
|
64
|
+
cite,
|
65
|
+
code,
|
66
|
+
dfn,
|
67
|
+
em,
|
68
|
+
strong,
|
69
|
+
th,
|
70
|
+
var {
|
71
|
+
font-style:normal;
|
72
|
+
font-weight:normal;
|
73
|
+
}
|
74
|
+
/*
|
75
|
+
TODO Figure out where this list-style rule is best set. Hedger has a request to investigate.
|
76
|
+
*/
|
77
|
+
li {
|
78
|
+
list-style:none;
|
79
|
+
}
|
80
|
+
|
81
|
+
caption,
|
82
|
+
th {
|
83
|
+
text-align:left;
|
84
|
+
}
|
85
|
+
h1,
|
86
|
+
h2,
|
87
|
+
h3,
|
88
|
+
h4,
|
89
|
+
h5,
|
90
|
+
h6 {
|
91
|
+
font-size:100%;
|
92
|
+
font-weight:normal;
|
93
|
+
}
|
94
|
+
q:before,
|
95
|
+
q:after {
|
96
|
+
content:'';
|
97
|
+
}
|
98
|
+
abbr,
|
99
|
+
acronym {
|
100
|
+
border:0;
|
101
|
+
font-variant:normal;
|
102
|
+
}
|
103
|
+
/* to preserve line-height and selector appearance */
|
104
|
+
sup {
|
105
|
+
vertical-align:text-top;
|
106
|
+
}
|
107
|
+
sub {
|
108
|
+
vertical-align:text-bottom;
|
109
|
+
}
|
110
|
+
input,
|
111
|
+
textarea,
|
112
|
+
select {
|
113
|
+
font-family:inherit;
|
114
|
+
font-size:inherit;
|
115
|
+
font-weight:inherit;
|
116
|
+
}
|
117
|
+
/*to enable resizing for IE*/
|
118
|
+
input,
|
119
|
+
textarea,
|
120
|
+
select {
|
121
|
+
*font-size:100%;
|
122
|
+
}
|
123
|
+
/*because legend doesn't inherit in IE */
|
124
|
+
legend {
|
125
|
+
color:#000;
|
126
|
+
}
|
data/data/templates/main.html
CHANGED
@@ -5,8 +5,12 @@
|
|
5
5
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
6
6
|
<head>
|
7
7
|
<title>Genit - Static web site framework</title>
|
8
|
+
<link rel="stylesheet" type="text/css" media="all" href="styles/alsa/all.css" />
|
9
|
+
<link rel="stylesheet" type="text/css" media="screen" href="styles/screen.css" />
|
10
|
+
<link rel="stylesheet" type="text/css" media="print" href="styles/print.css" />
|
8
11
|
</head>
|
9
12
|
<body>
|
13
|
+
<genit class="menu" />
|
10
14
|
<genit class="pages" />
|
11
15
|
</body>
|
12
16
|
</html>
|
data/lib/genit.rb
CHANGED
data/lib/genit/builder.rb
CHANGED
@@ -9,7 +9,7 @@ module Genit
|
|
9
9
|
|
10
10
|
# Public: Constructor.
|
11
11
|
#
|
12
|
-
# document - A Nokogiri::
|
12
|
+
# document - A Nokogiri::XML::Document
|
13
13
|
def initialize document
|
14
14
|
@document = document
|
15
15
|
end
|
@@ -24,13 +24,36 @@ module Genit
|
|
24
24
|
#
|
25
25
|
# doc = builder.replace('genit.pages', "<working />")
|
26
26
|
#
|
27
|
-
# Return the
|
27
|
+
# Return the updated Nokogiri::XML::Document document.
|
28
28
|
def replace css_rule, replacement
|
29
29
|
tag = @document.at_css(css_rule)
|
30
30
|
tag.replace replacement
|
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
|
+
|
34
57
|
end
|
35
58
|
|
36
59
|
end
|
data/lib/genit/compiler.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
+
require 'fileutils'
|
4
|
+
|
3
5
|
module Genit
|
4
6
|
|
5
|
-
#
|
7
|
+
# Web site "compiler".
|
6
8
|
class Compiler
|
7
9
|
|
8
10
|
# Public: Constructor.
|
@@ -12,37 +14,31 @@ module Genit
|
|
12
14
|
@working_dir = working_dir
|
13
15
|
end
|
14
16
|
|
15
|
-
# Public:
|
17
|
+
# Public: Compile the web site.
|
16
18
|
def compile
|
17
|
-
|
18
|
-
|
19
|
-
process file
|
20
|
-
end
|
19
|
+
compile_pages
|
20
|
+
FileUtils.cp_r File.join(@working_dir, 'styles'), File.join(@working_dir, 'www')
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
def load_files file
|
32
|
-
@template = HtmlDocument.open(File.join(@working_dir, 'templates/main.html'))
|
33
|
-
@page_content = HtmlDocument.open_as_string(File.join(@working_dir, 'pages', file))
|
25
|
+
def compile_pages
|
26
|
+
Dir.foreach(File.join(@working_dir, 'pages')) do |file|
|
27
|
+
next if (file == ".") or (file == "..")
|
28
|
+
@filename = file
|
29
|
+
compile_page
|
30
|
+
end
|
34
31
|
end
|
35
32
|
|
36
|
-
def
|
37
|
-
|
38
|
-
@template =
|
33
|
+
def compile_page
|
34
|
+
pc = PageCompiler.new @working_dir, @filename
|
35
|
+
@template = pc.compile
|
36
|
+
save_file_as_html
|
39
37
|
end
|
40
38
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
out.puts @template.to_html
|
45
|
-
end
|
39
|
+
def save_file_as_html
|
40
|
+
doc_writer = DocumentWriter.new @working_dir
|
41
|
+
doc_writer.save_as_html @template, @filename
|
46
42
|
end
|
47
43
|
|
48
44
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
module Genit
|
6
|
+
|
7
|
+
# Write an html or xml document.
|
8
|
+
class DocumentWriter
|
9
|
+
|
10
|
+
# Public: Constructor.
|
11
|
+
#
|
12
|
+
# working_dir - The String working directory, where live the project.
|
13
|
+
def initialize working_dir
|
14
|
+
@working_dir = working_dir
|
15
|
+
end
|
16
|
+
|
17
|
+
# Save the document as an html file.
|
18
|
+
#
|
19
|
+
# document - A Nokogiri::HTML or Nokogiri::XML document
|
20
|
+
# filename - The String name of the future saved document
|
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
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/genit/html_document.rb
CHANGED
@@ -10,9 +10,9 @@ module Genit
|
|
10
10
|
|
11
11
|
# Public: Open a html document.
|
12
12
|
#
|
13
|
-
# file - Full path String filename
|
13
|
+
# file - Full path String filename.
|
14
14
|
#
|
15
|
-
# Returns a Nokogiri::HTML document
|
15
|
+
# Returns a Nokogiri::HTML document.
|
16
16
|
def self.open file
|
17
17
|
Nokogiri::HTML(File.open(file))
|
18
18
|
end
|
@@ -21,13 +21,22 @@ module Genit
|
|
21
21
|
#
|
22
22
|
# file - Full path String name of a html or markdown file.
|
23
23
|
#
|
24
|
-
# Returns a String
|
24
|
+
# Returns a String.
|
25
25
|
def self.open_as_string file
|
26
26
|
string = IO.read file
|
27
27
|
string = BlueCloth.new(string).to_html if file.end_with? '.markdown'
|
28
28
|
string
|
29
29
|
end
|
30
30
|
|
31
|
+
# Public: Get the list of <genit> tag in a document.
|
32
|
+
#
|
33
|
+
# file - Nokogiri::HTML document.
|
34
|
+
#
|
35
|
+
# Returns a list of Nokogiri::XML::NodeSet.
|
36
|
+
def self.genit_tags_from file
|
37
|
+
file.css "genit"
|
38
|
+
end
|
39
|
+
|
31
40
|
end
|
32
41
|
|
33
42
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
module Genit
|
6
|
+
|
7
|
+
# Compile a single page.
|
8
|
+
class PageCompiler
|
9
|
+
|
10
|
+
# Public: Constructor.
|
11
|
+
#
|
12
|
+
# working_dir - The String working directory, where live the project.
|
13
|
+
# filename - The String name of the page
|
14
|
+
def initialize working_dir, filename
|
15
|
+
@working_dir = working_dir
|
16
|
+
@filename = filename
|
17
|
+
@template = HtmlDocument.open(File.join(@working_dir, 'templates/main.html'))
|
18
|
+
end
|
19
|
+
|
20
|
+
# Public: Compile the page.
|
21
|
+
#
|
22
|
+
# Returns a Nokogiri::HTML document.
|
23
|
+
def compile
|
24
|
+
genit_tags = HtmlDocument.genit_tags_from @template
|
25
|
+
genit_tags.each {|tag| process_tag tag }
|
26
|
+
@template
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def process_tag tag
|
32
|
+
case tag['class']
|
33
|
+
when 'pages' then tag_pages
|
34
|
+
when 'menu' then tag_menu
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Remplace la page au sein du template
|
39
|
+
def tag_pages
|
40
|
+
@page_content = HtmlDocument.open_as_string(File.join(@working_dir, 'pages', @filename))
|
41
|
+
builder = Builder.new(@template)
|
42
|
+
@template = builder.replace('genit.pages', @page_content)
|
43
|
+
end
|
44
|
+
|
45
|
+
def tag_menu
|
46
|
+
build_menu
|
47
|
+
replace_menu_into_template
|
48
|
+
end
|
49
|
+
|
50
|
+
def build_menu
|
51
|
+
menu = XmlDocument.open(File.join(@working_dir, "templates/menu.html"))
|
52
|
+
builder = Builder.new(menu)
|
53
|
+
@menu = builder.select_menu(@filename)
|
54
|
+
end
|
55
|
+
|
56
|
+
def replace_menu_into_template
|
57
|
+
builder = Builder.new(@template)
|
58
|
+
@template = builder.replace('genit.menu', @menu.to_html)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -22,8 +22,11 @@ module Genit
|
|
22
22
|
begin
|
23
23
|
FileUtils.makedirs @name
|
24
24
|
create_dirs ['news', 'pages', 'scripts', 'styles', 'templates', 'www']
|
25
|
-
create_dirs ['styles/
|
26
|
-
copy_files ['templates/main.html', '
|
25
|
+
create_dirs ['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']
|
27
30
|
rescue SystemCallError
|
28
31
|
puts "Cannot create project..."
|
29
32
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'bluecloth'
|
5
|
+
|
6
|
+
module Genit
|
7
|
+
|
8
|
+
# Open an xml file.
|
9
|
+
class XmlDocument
|
10
|
+
|
11
|
+
# Public: Open an xml document.
|
12
|
+
#
|
13
|
+
# file - Full path String filename.
|
14
|
+
#
|
15
|
+
# Returns a Nokogiri::XML document.
|
16
|
+
def self.open file
|
17
|
+
Nokogiri::XML(File.open(file))
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/spec/builder_spec.rb
CHANGED
@@ -14,4 +14,12 @@ describe Builder do
|
|
14
14
|
doc.css("body working").size.should == 1
|
15
15
|
end
|
16
16
|
|
17
|
+
it "should set the menu" do
|
18
|
+
menu = Nokogiri::XML(File.open("data/templates/menu.html"))
|
19
|
+
builder = Builder.new(menu)
|
20
|
+
menu = builder.select_menu('index.html')
|
21
|
+
menu.css("ul#menu a#selected").size.should == 1
|
22
|
+
menu.css("ul#menu a#selected").first['href'].should == 'index.html'
|
23
|
+
end
|
24
|
+
|
17
25
|
end
|
data/spec/compiler_spec.rb
CHANGED
@@ -32,4 +32,14 @@ describe Compiler do
|
|
32
32
|
File.exist?('spec/project-name/www/doc.html').should == true
|
33
33
|
end
|
34
34
|
|
35
|
+
it "should copy the styles/ into www/" do
|
36
|
+
File.exist?('spec/project-name/www/styles/screen.css').should be_true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should set the menu in index page" do
|
40
|
+
@compiler.compile
|
41
|
+
doc = Nokogiri::HTML(File.open("spec/project-name/www/index.html"))
|
42
|
+
doc.at_css("ul#menu a#selected")['href'].should == 'index.html'
|
43
|
+
end
|
44
|
+
|
35
45
|
end
|
data/spec/html_document_spec.rb
CHANGED
@@ -20,4 +20,10 @@ describe HtmlDocument do
|
|
20
20
|
content.should == '<h1>title</h1>'
|
21
21
|
end
|
22
22
|
|
23
|
+
it "should extract the list of genit tags" do
|
24
|
+
doc = HtmlDocument.open("data/templates/main.html")
|
25
|
+
tags = HtmlDocument.genit_tags_from doc
|
26
|
+
tags.size.should == 2
|
27
|
+
end
|
28
|
+
|
23
29
|
end
|
data/spec/nokogiri_spec.rb
CHANGED
@@ -12,15 +12,18 @@ describe "Nokogiri library" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should retrieve all genit tag" do
|
15
|
-
@doc.css("body genit").size.should ==
|
15
|
+
@doc.css("body genit").size.should == 2
|
16
16
|
end
|
17
17
|
|
18
|
-
it "should retrieve
|
19
|
-
@doc.
|
18
|
+
it "should retrieve class of tag" do
|
19
|
+
tags = @doc.css("body genit")
|
20
|
+
tags[0]['class'].should == "menu"
|
21
|
+
tags[1]['class'].should == "pages"
|
20
22
|
end
|
21
23
|
|
22
|
-
it "should
|
23
|
-
@doc.at_css("body
|
24
|
+
it "should add an attribute" do
|
25
|
+
@doc.at_css("body")['class'] = "main"
|
26
|
+
@doc.at_css("body")['class'].should == 'main'
|
24
27
|
end
|
25
28
|
|
26
29
|
end
|
@@ -49,16 +49,12 @@ describe ProjectCreator do
|
|
49
49
|
File.exist?('spec/project-name/www').should == true
|
50
50
|
end
|
51
51
|
|
52
|
-
it "should create a
|
53
|
-
File.exist?('spec/project-name/styles/
|
52
|
+
it "should create a alsa folder inside the styles" do
|
53
|
+
File.exist?('spec/project-name/styles/alsa').should == true
|
54
54
|
end
|
55
55
|
|
56
|
-
it "should create a
|
57
|
-
File.exist?('spec/project-name/styles/
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should create a css/yui folder inside the styles" do
|
61
|
-
File.exist?('spec/project-name/styles/css/yui').should == true
|
56
|
+
it "should create a yui folder inside the styles" do
|
57
|
+
File.exist?('spec/project-name/styles/yui').should == true
|
62
58
|
end
|
63
59
|
|
64
60
|
it "should create a images folder inside the styles" do
|
@@ -67,16 +63,28 @@ describe ProjectCreator do
|
|
67
63
|
|
68
64
|
end # "Folder structure"
|
69
65
|
|
70
|
-
|
66
|
+
|
71
67
|
|
68
|
+
describe "The templates folder" do
|
72
69
|
it "should have got templates/main.html" do
|
73
70
|
File.exist?('data/templates/main.html').should be_true
|
74
71
|
end
|
75
|
-
|
72
|
+
|
76
73
|
it "should copy templates/main.html" do
|
77
74
|
File.exist?('spec/project-name/templates/main.html').should be_true
|
78
75
|
end
|
76
|
+
|
77
|
+
it "should have got templates/menu.html" do
|
78
|
+
File.exist?('data/templates/menu.html').should be_true
|
79
|
+
end
|
79
80
|
|
81
|
+
it "should copy templates/menu.html" do
|
82
|
+
File.exist?('spec/project-name/templates/menu.html').should be_true
|
83
|
+
end
|
84
|
+
|
85
|
+
end # "The templates folder"
|
86
|
+
|
87
|
+
describe "The pages folder" do
|
80
88
|
it "should have got pages/index.html" do
|
81
89
|
File.exist?('data/pages/index.html').should be_true
|
82
90
|
end
|
@@ -84,7 +92,75 @@ describe ProjectCreator do
|
|
84
92
|
it "should copy pages/index.html" do
|
85
93
|
File.exist?('spec/project-name/pages/index.html').should be_true
|
86
94
|
end
|
95
|
+
end # "The pages folder"
|
96
|
+
|
97
|
+
describe "The styles folder" do
|
98
|
+
it "should have got styles/handheld.css" do
|
99
|
+
File.exist?('data/styles/handheld.css').should be_true
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should copy styles/handheld.css" do
|
103
|
+
File.exist?('spec/project-name/styles/handheld.css').should be_true
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should have got styles/print.css" do
|
107
|
+
File.exist?('data/styles/print.css').should be_true
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should copy styles/print.css" do
|
111
|
+
File.exist?('spec/project-name/styles/print.css').should be_true
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should have got styles/screen.css" do
|
115
|
+
File.exist?('data/styles/screen.css').should be_true
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should copy styles/screen.css" do
|
119
|
+
File.exist?('spec/project-name/styles/screen.css').should be_true
|
120
|
+
end
|
87
121
|
|
88
|
-
|
122
|
+
it "should have got styles/alsa/all.css" do
|
123
|
+
File.exist?('data/styles/alsa/all.css').should be_true
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should copy styles/alsa/all.css" do
|
127
|
+
File.exist?('spec/project-name/styles/alsa/all.css').should be_true
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should have got styles/yui/all.css" do
|
131
|
+
File.exist?('data/styles/yui/all.css').should be_true
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should copy styles/yui/all.css" do
|
135
|
+
File.exist?('spec/project-name/styles/yui/all.css').should be_true
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should have got styles/yui/base.css" do
|
139
|
+
File.exist?('data/styles/yui/base.css').should be_true
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should copy styles/yui/base.css" do
|
143
|
+
File.exist?('spec/project-name/styles/yui/base.css').should be_true
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should have got styles/yui/fonts.css" do
|
147
|
+
File.exist?('data/styles/yui/fonts.css').should be_true
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should copy styles/yui/fonts.css" do
|
151
|
+
File.exist?('spec/project-name/styles/yui/fonts.css').should be_true
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should have got styles/yui/reset.css" do
|
155
|
+
File.exist?('data/styles/yui/reset.css').should be_true
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should copy styles/yui/reset.css" do
|
159
|
+
File.exist?('spec/project-name/styles/yui/reset.css').should be_true
|
160
|
+
end
|
161
|
+
|
162
|
+
end # "The styles folder"
|
163
|
+
|
164
|
+
|
89
165
|
|
90
166
|
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.2'
|
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-07-02 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: &82395440 !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: *82395440
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: nokogiri
|
28
|
-
requirement: &
|
28
|
+
requirement: &82395100 !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: *82395100
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bluecloth
|
39
|
-
requirement: &
|
39
|
+
requirement: &82394760 !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: *82394760
|
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,10 +60,22 @@ files:
|
|
60
60
|
- lib/genit/project_creator.rb
|
61
61
|
- lib/genit/html_document.rb
|
62
62
|
- lib/genit/builder.rb
|
63
|
+
- lib/genit/xml_document.rb
|
64
|
+
- lib/genit/page_compiler.rb
|
63
65
|
- lib/genit/compiler.rb
|
66
|
+
- lib/genit/document_writer.rb
|
64
67
|
- lib/genit.rb
|
65
68
|
- bin/genit
|
69
|
+
- data/templates/menu.html
|
66
70
|
- data/templates/main.html
|
71
|
+
- data/styles/handheld.css
|
72
|
+
- data/styles/print.css
|
73
|
+
- data/styles/alsa/all.css
|
74
|
+
- data/styles/screen.css
|
75
|
+
- data/styles/yui/reset.css
|
76
|
+
- data/styles/yui/all.css
|
77
|
+
- data/styles/yui/base.css
|
78
|
+
- data/styles/yui/fonts.css
|
67
79
|
- data/pages/index.html
|
68
80
|
- spec/compiler_spec.rb
|
69
81
|
- spec/builder_spec.rb
|
@@ -73,6 +85,7 @@ files:
|
|
73
85
|
- spec/project_creator_spec.rb
|
74
86
|
- spec/bluecloth_spec.rb
|
75
87
|
- spec/test-files/test.markdown
|
88
|
+
- spec/xml_document_spec.rb
|
76
89
|
- VERSION
|
77
90
|
- NEWS
|
78
91
|
- README.markdown
|