summaryrefslogtreecommitdiffstats
path: root/test
blob: 3d2e28a24c3e633340157acf1620d3ee428a07a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/usr/bin/env zsh

DIR=`dirname $0`
CMD=`basename $0`
{ test -r $DIR } || {
    echo "error: launch webnomad commands from your project directory"
    echo "i.e: ./$DIR/$CMD"
    return 1
}

source ${DIR}/utils

{ test -r config.zsh } || {
    error "Directory not configured for WebNomad. First use ./webnomad/init"
    exit 1 }

source config.zsh

notice "Rendering $BRAND website"
act "Title: $TITLE"


source ${DIR}/render source

# Main

mkdir -p test
mkdir -p test/css
# side menu stylesheet
cp $DIR/css/jquery.sidr.dark.css test/css

fonts=('Arial' 'Arial Black' 'Comic Sans MS' 'Courier New' 'Georgia' 'Impact' 'Monaco' 'Lucida Grande')
fonts+=('Book Antiqua' 'Tahoma' 'Times New Roman' 'Trebuchet MS' 'Verdana' 'Geneva' 'New York')
custom_fonts=()
total_fonts=${#fonts}
# string match case insensitive
unsetopt CASE_GLOB

# if there are custom fonts add them
{ test -d fonts } && {
    notice "Indexing custom fonts"
    rm -f test/css/custom.fonts.css
    mkdir -p test/fonts
    ttf=`find -L fonts -iname '*.ttf'`
    for f in ${(f)ttf}; do
	ffile=`basename "$f"`
	cp "$f" test/css/"$ffile"
	custom_fonts+=("${ffile%.ttf}")
	cat <<EOF >> test/css/custom.fonts.css
	@font-face { font-family: '${ffile%.ttf}';
             src: url('$ffile') format('truetype'); }
EOF
	total_fonts=$(( $total_fonts + 1 ))
    done
    otf=`find -L fonts -iname '*.otf'`
    for f in ${(f)otf}; do
	ffile=`basename "$f"`
	cp "$f" test/css/"$ffile"
	custom_fonts+=("${ffile%.otf}")
	cat <<EOF >> test/css/custom.fonts.css
	@font-face { font-family: '${ffile%.otf}';
             src: url('$ffile') format('opentype'); }
EOF
	total_fonts=$(( $total_fonts + 1 ))
    done


    act "$total_fonts custom fonts indexed"
}

fonts=($custom_fonts $fonts)

# render all HTML views
htmls=(`find views -type f -name '*.html'`)
for src in $htmls; do
    # read meta commands
    cat ${src} | read_meta

    # compute destination file
    dst="test/`basename ${src%.*}`$EXTENSION"

    render_header > $dst

    # close <head> as nothing else is needed
    cat <<EOF >> $dst

<link rel="stylesheet" href="css/jquery.sidr.dark.css">
<link rel="stylesheet" href="css/custom.fonts.css">

</head> <!-- end of <head> -->

<body>
  <div class="container">
EOF

    # navbar
    cat tmpl/navbar.html >> $dst

    # start the body of article
    cat <<EOF >> $dst
<p>&nbsp;</p>
<a id="menu" href="#sidr">Design test</a>

<article>
EOF

    # render html
    act -n "Html rendering: $dst "
    cat $src | render_html >> $dst

cat <<EOF >> $dst
</article>
<p>&nbsp;</p>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.sidr.js"></script>

 
<div id="sidr">
  <h3>Design test</h3>
EOF


# Font size selector

font-size_select() {
    cat <<EOF
 <select id="$1" name="$1-font-size">
EOF
    c=.5
    while [[ $c -le 8 ]]; do
	cat <<EOF
<option value="${c%.}">${c%.} em</option>
EOF
	c=$(( $c + .5 ))
    done
    cat <<EOF
</select>
EOF
}

print  "<h4>H1 font size</h3>" >> $dst
font-size_select h1size >> $dst

print  "<h4>H2 font size</h3>" >> $dst
font-size_select h2size >> $dst



# font family selector

font-family_select() {
	cat <<EOF
<select id="$1" name="$1-font-family">
EOF
    for f in $fonts; do
	cat <<EOF
<option value="$f">$f</option>
EOF
    done
    print "</select>"
}
	

cat <<EOF >> $dst
  <h3>Brand font family</h3>
EOF
font-family_select brand-font-family >> $dst

cat <<EOF >> $dst
  <h3>Header font family</h3>
EOF
font-family_select header-font-family >> $dst

cat <<EOF >> $dst
  <h3>Body font family</h3>
EOF
font-family_select body-font-family >> $dst

cat <<EOF >> $dst
  <h3>Navigation Font family</h3>
EOF
font-family_select nav-font-family >> $dst


cat <<EOF  >> $dst

</div>

<script>
\$(document).ready(function() {
  \$('#menu').sidr({
     name: 'sidr',
     side: 'right',
     displace: false
});
});
\$('#h1size').change(function() { \$('h1').css('font-size', \$('#h1size').val() + "em" ); })
\$('#h2size').change(function() { \$('h2').css('font-size', \$('#h2size').val() + "em" ); })

\$('#brand-font-family').change(function(){ \$('.navbar .brand').css('font-family', \$('#brand-font-family').val() ); })

\$('#header-font-family').change(function(){ \$('h1').css('font-family', \$('#header-font-family').val() ); })
\$('#header-font-family').change(function(){ \$('h2').css('font-family', \$('#header-font-family').val() ); })

\$('#body-font-family').change(function(){ \$('body').css('font-family', \$('#body-font-family').val() ); })

\$('#nav-font-family').change(function(){ \$('nav div div ul li a').css('font-family', \$('#nav-font-family').val() ); })

</script>

EOF

    render_footer >> $dst

    act "done"

done


for m in `find views -mindepth 1 -type d `; do
    act -n "publishing $m... "
    rsync -r $m test/
    print "done"
done

# add design test libs
mkdir -p test/js
cp $DIR/js/jquery.min.js test/js
cp $DIR/js/jquery.sidr.js test/js