easy_html_creator 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ 0.1.2
2
+ =================
3
+ Project helper and add actionview for hml files
4
+
5
+ 0.1.1
6
+ =================
7
+ Copy images and other static files
8
+
9
+ 0.1.0
10
+ =================
11
+ Add SASS and CoffeeScript
12
+
13
+ 0.0.2
14
+ =================
15
+ Dynamic rendering and remove all old files before rendering
16
+
17
+ 0.0.1
18
+ =================
19
+ First working version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ ruby '2.1.3'
3
+
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014, Tom Hanolt and Dennis van de Hoef
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,51 @@
1
+ easy-html-creator
2
+ =================
3
+ Easy_html_creator is a gem that makes developing static HTML websites easy and joyful.
4
+
5
+ Once you learned the joy of haml or sass, it get boring to program in "plain old" html and css.
6
+
7
+ Using our Gem you could generate and maintain multiple static websites and program them in your preferred languages.
8
+
9
+ Currently supported by our fast and lightweight re-generation server:
10
+ HAML
11
+ Sass (with bootstarp)
12
+ CoffeeScript
13
+
14
+ We also included the "actionview" gem, to enable the use of rails standard functions like "text_field_tag".
15
+
16
+ Installation
17
+ =======
18
+ Add folliwing to your Gemfile
19
+
20
+ `gem 'easy-html-editor'`
21
+
22
+ than run
23
+
24
+ `bundle install`
25
+
26
+ Usage
27
+ =======
28
+
29
+ `initDevRoot`
30
+ This command will generate a sample dev_root and web_root folder
31
+
32
+ `generateFiles`
33
+ This command will generate all the files
34
+
35
+ `startServer`
36
+ This command will start a webserver with will automatically regenerate all the files
37
+
38
+
39
+ TODO
40
+ ========
41
+ - clean/refactor code
42
+ - Add tests
43
+
44
+ Credits
45
+ =======
46
+
47
+ ./ruby_files/generate.rb (*in the first commit and/or version 0.0.1*) is based on:
48
+ https://github.com/scarpenter/command_line_haml/blob/master/generate.rb
49
+
50
+ ./ruby_files/server.rb (*in the first commit and/or version 0.0.1*) is based on:
51
+ https://practicingruby.com/articles/implementing-an-http-file-server
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'generator/generator'
4
+
5
+ Generator::Generator.new.generate
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+
5
+ source_dir = File.expand_path(File.dirname(__FILE__))[0..-4]
6
+ output_folder = "#{Dir.pwd}/dev_root"
7
+
8
+ puts "Creating dev_root with sample website"
9
+
10
+ unless File.directory? output_folder
11
+ FileUtils::mkdir_p output_folder
12
+ FileUtils::copy_entry("#{source_dir}dev_root", output_folder)
13
+ end
14
+
15
+ puts "Createweb_root directory"
16
+
17
+ unless File.directory? "#{Dir.pwd}/web_root"
18
+ FileUtils::mkdir_p "#{Dir.pwd}/web_root"
19
+ end
20
+
21
+ puts "All done, use 'startServer' to start the development server."
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'easy_html_creator'
@@ -0,0 +1,40 @@
1
+ module ActivesupportOverride
2
+ def stylesheet_link_tag(path, media='screen')
3
+ '<link href="'+path_to_css(path)+'" media="'+media+'" rel="stylesheet" type="text/css" />'
4
+ end
5
+
6
+ def javascript_include_tag(path)
7
+ '<script src="'+path_to_js(path)+'"></script>'
8
+ end
9
+
10
+ def meta_tag(type, content)
11
+ '<meta name="'+type+'" content="'+content+'" />'
12
+ end
13
+
14
+ def meta_tag_http(type, content)
15
+ '<meta http-equiv="'+type+'" content="'+content+'" />'
16
+ end
17
+
18
+ def link_tag(source, relation, type)
19
+ '<link rel="'+relation+'" href="'+source+'" type="'+type+'" />'
20
+ end
21
+
22
+ def path_to_css(path)
23
+ return path if external_path?(path)
24
+ "css/#{path}"
25
+ end
26
+
27
+ def path_to_js(path)
28
+ return path if external_path? path
29
+ "js/#{path}"
30
+ end
31
+
32
+ def path_to_image(path)
33
+ return path if external_path? path
34
+ "images/#{path}"
35
+ end
36
+
37
+ def external_path? path
38
+ path.start_with?('//') || path.start_with?('http')
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ module SharedHelper
2
+ def sharedhelper_method
3
+ 'sharedhelper_method'
4
+ end
5
+ end
@@ -0,0 +1,266 @@
1
+ /* -------------------------------------------------------------
2
+ * Sass CSS3 Mixins! The Cross-Browser CSS3 Sass Library
3
+ * By: Matthieu Aussaguel, http://www.mynameismatthieu.com, @matthieu_tweets
4
+ *
5
+ * List of CSS3 Sass Mixins File to be @imported and @included as you need
6
+ *
7
+ * The purpose of this library is to facilitate the use of CSS3 on different browsers avoiding HARD TO READ and NEVER
8
+ * ENDING css files
9
+ *
10
+ * note: All CSS3 Properties are being supported by Safari 5
11
+ * more info: http://www.findmebyip.com/litmus/#css3-properties
12
+ *
13
+ * Mixins available:
14
+ * - background-gradient - arguments: Start Color: #3C3C3C, End Color: #999999
15
+ * - background-size - arguments: Width: 100%, Height: 100%
16
+ * - border-radius - arguments: Radius: 5px
17
+ * - border-radius-separate - arguments: Top Left: 5px, Top Left: 5px, Bottom Left: 5px, Bottom Right: 5px
18
+ * - box - arguments: Orientation: horizontal, Pack: center, Align: center
19
+ * - box-rgba - arguments: R: 60, G: 3, B: 12, Opacity: 0.23, Color: #3C3C3C
20
+ * - box-shadow - arguments: X: 2px, Y: 2px, Blur: 5px, Color: rgba(0,0,0,.4, inset: "")
21
+ * - box-sizing - arguments: Type: border-box
22
+ * - columns - arguments: Count: 3, Gap: 10
23
+ * - double-borders - arguments: Color One: #3C3C3C, Color Two: #999999, Radius: 0
24
+ * - flex - arguments: Value: 1
25
+ * - flip - arguments: ScaleX: -1
26
+ * - font-face - arguments: Font Family: myFont, Eot File Src: myFont.eot, Woff File Src: myFont.woff, Ttf File Src: myFont.ttf
27
+ * - opacity - arguments: Opacity: 0.5
28
+ * - outline radius - arguments: Radius: 5px
29
+ * - resize - arguments: Direction: both
30
+ * - rotate - arguments: Degree: 0, M11: 0, M12: 0, M21: 0, M22: 0
31
+ * CSS Matrix Rotation Calculator http://www.boogdesign.com/examples/transforms/matrix-calculator.html
32
+ * - text-shadow - arguments: X: 2px, Y: 2px, Blur: 5px, Color: rgba(0,0,0,.4)
33
+ * - transform - arguments: Parameters: null
34
+ * - transition - arguments: What: all, Length: 1s, Easing: ease-in-out
35
+ * - triple-borders - arguments: Color One: #3C3C3C, Color Two: #999999, Color Three: #000000, Radius: 0
36
+ *
37
+ *-------------------------------------------------------------*/
38
+
39
+ /* BACKGROUND GRADIENT */
40
+ @mixin background-gradient($startColor: #3C3C3C, $endColor: #999999)
41
+ background-color: $startColor
42
+ background-image: -webkit-gradient(linear, left top, left bottom, from($startColor), to($endColor))
43
+ background-image: -webkit-linear-gradient(top, $startColor, $endColor)
44
+ background-image: -moz-linear-gradient(top, $startColor, $endColor)
45
+ background-image: -ms-linear-gradient(top, $startColor, $endColor)
46
+ background-image: -o-linear-gradient(top, $startColor, $endColor)
47
+ background-image: linear-gradient(top, $startColor, $endColor)
48
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#{$startColor}', endColorStr='#{$endColor}')
49
+
50
+
51
+ /* BACKGROUND SIZE */
52
+ @mixin background-size($width: 100%, $height: 100%)
53
+ -moz-background-size: $width $height
54
+ -webkit-background-size: $width $height
55
+ background-size: $width $height
56
+
57
+
58
+ /* BORDER RADIUS */
59
+ @mixin border-radius($radius: 5px)
60
+ -moz-border-radius: $radius
61
+ -webkit-border-radius: $radius
62
+ border-radius: $radius
63
+
64
+ @mixin border-radius-separate($topLeftRadius: 5px, $topRightRadius: 5px, $bottomLeftRadius: 5px, $bottomRightRadius: 5px)
65
+ -webkit-border-top-left-radius: $topLeftRadius
66
+ -webkit-border-top-right-radius: $topRightRadius
67
+ -webkit-border-bottom-right-radius: $bottomRightRadius
68
+ -webkit-border-bottom-left-radius: $bottomLeftRadius
69
+
70
+ -moz-border-radius-topleft: $topLeftRadius
71
+ -moz-border-radius-topright: $topRightRadius
72
+ -moz-border-radius-bottomright: $bottomRightRadius
73
+ -moz-border-radius-bottomleft: $bottomLeftRadius
74
+
75
+ border-top-left-radius: $topLeftRadius
76
+ border-top-right-radius: $topRightRadius
77
+ border-bottom-right-radius: $bottomRightRadius
78
+ border-bottom-left-radius: $bottomLeftRadius
79
+
80
+ /* BOX */
81
+ @mixin box($orient: horizontal, $pack: center, $align: center)
82
+ display: -webkit-box
83
+ display: -moz-box
84
+ display: box
85
+
86
+ -webkit-box-orient: $orient
87
+ -moz-box-orient: $orient
88
+ box-orient: $orient
89
+
90
+ -webkit-box-pack: $pack
91
+ -moz-box-pack: $pack
92
+ box-pack: $pack
93
+
94
+ -webkit-box-align: $align
95
+ -moz-box-align: $align
96
+ box-align: $align
97
+
98
+ /* BOX RGBA */
99
+ @mixin box-rgba($r: 60, $g: 3, $b: 12, $opacity: 0.23, $color: #3C3C3C)
100
+ background-color: transparent
101
+ background-color: rgba($r, $g, $b, $opacity)
102
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$color}',endColorstr='#{$color}')
103
+ zoom: 1
104
+
105
+
106
+ /* BOX SHADOW */
107
+ @mixin box-shadow($x: 2px, $y: 2px, $blur: 5px, $color: rgba(0,0,0,.4), $inset: "")
108
+ @if ($inset != "")
109
+ -webkit-box-shadow: $inset $x $y $blur $color
110
+ -moz-box-shadow: $inset $x $y $blur $color
111
+ box-shadow: $inset $x $y $blur $color
112
+ @else
113
+ -webkit-box-shadow: $x $y $blur $color
114
+ -moz-box-shadow: $x $y $blur $color
115
+ box-shadow: $x $y $blur $color
116
+
117
+ /* BOX SIZING */
118
+ @mixin box-sizing($type: border-box)
119
+ -webkit-box-sizing: $type
120
+ -moz-box-sizing: $type
121
+ box-sizing: $type
122
+
123
+ /* COLUMNS */
124
+ @mixin columns($count: 3, $gap: 10)
125
+ -webkit-column-count: $count
126
+ -moz-column-count: $count
127
+ column-count: $count
128
+
129
+ -webkit-column-gap: $gap
130
+ -moz-column-gap: $gap
131
+ column-gap: $gap
132
+
133
+ /* DOUBLE BORDERS */
134
+ @mixin double-borders($colorOne: #3C3C3C, $colorTwo: #999999, $radius: 0)
135
+ border: 1px solid $colorOne
136
+
137
+ -webkit-box-shadow: 0 0 0 1px $colorTwo
138
+ -moz-box-shadow: 0 0 0 1px $colorTwo
139
+ box-shadow: 0 0 0 1px $colorTwo
140
+
141
+ @include border-radius( $radius )
142
+
143
+ /* FLEX */
144
+ @mixin flex($value: 1)
145
+ -webkit-box-flex: $value
146
+ -moz-box-flex: $value
147
+ box-flex: $value
148
+
149
+ /* FLIP */
150
+ @mixin flip($scaleX: -1)
151
+ -moz-transform: scaleX($scaleX)
152
+ -o-transform: scaleX($scaleX)
153
+ -webkit-transform: scaleX($scaleX)
154
+ transform: scaleX($scaleX)
155
+ filter: FlipH
156
+ -ms-filter: "FlipH"
157
+
158
+ /* FONT FACE */
159
+ @mixin font-face($fontFamily: myFont, $eotFileSrc: 'myFont.eot', $woffFileSrc: 'myFont.woff', $ttfFileSrc: 'myFont.ttf')
160
+ font-family: $fontFamily
161
+ src: url($eotFileSrc) format('eot'), url($woffFileSrc) format('woff'), url($ttfFileSrc) format('truetype')
162
+
163
+ /* OPACITY */
164
+ @mixin opacity($opacity: 0.5)
165
+ filter: alpha(opacity=($opacity * 100))
166
+ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=" + ($opacity * 100) + ")"
167
+ -moz-opacity: $opacity
168
+ -khtml-opacity: $opacity
169
+ opacity: $opacity
170
+
171
+
172
+ /* OUTLINE RADIUS */
173
+ @mixin outline-radius($radius: 5px)
174
+ -webkit-outline-radius: $radius
175
+ -moz-outline-radius: $radius
176
+ outline-radius: $radius
177
+
178
+ /* RESIZE */
179
+ @mixin resize($direction: both)
180
+ -webkit-resize: $direction
181
+ -moz-resize: $direction
182
+ resize: $direction
183
+
184
+ /* ROTATE*/
185
+ @mixin rotate($deg: 0, $m11: 0, $m12: 0, $m21: 0, $m22: 0)
186
+ -moz-transform: rotate($deg + deg)
187
+ -o-transform: rotate($deg + deg)
188
+ -webkit-transform: rotate($deg + deg)
189
+ -ms-transform: rotate($deg + deg)
190
+ transform: rotate($deg + deg)
191
+ filter: progid:DXImageTransform.Microsoft.Matrix(M11=#{$m11}, M12=#{$m12}, M21=#{$m21}, M22=#{$m22}, sizingMethod='auto expand')
192
+ zoom: 1
193
+
194
+ /* TEXT SHADOW */
195
+ @mixin text-shadow($x: 2px, $y: 2px, $blur: 5px, $color: rgba(0,0,0,.4))
196
+ text-shadow: $x $y $blur $color
197
+
198
+ /* TRANSFORM */
199
+ @mixin transform($params)
200
+ -webkit-transform: $params
201
+ -moz-transform: $params
202
+ transform: $params
203
+
204
+ /* TRANSITION */
205
+ @mixin transition($what: all, $length: 1s, $easing: ease-in-out)
206
+ -moz-transition: $what $length $easing
207
+ -o-transition: $what $length $easing
208
+ -webkit-transition: $what $length $easing
209
+ -ms-transition: $what $length $easing
210
+ transition: $what $length $easing
211
+
212
+ @mixin multi-transition($args...)
213
+ -moz-transition: $args
214
+ -o-transition: $args
215
+ -webkit-transition: $args
216
+ -ms-transition: $args
217
+ transition: $args
218
+
219
+ @mixin transform-transition($length, $easing: linear)
220
+ -moz-transition: -moz-transform $length $easing
221
+ -o-transition: -o-transform $length $easing
222
+ -webkit-transition: -webkit-transform $length $easing
223
+ -ms-transition: -ms-transform $length $easing
224
+ transition: transform $length $easing
225
+
226
+ @mixin transition-timing($timing_function)
227
+ -webkit-transition-timing-function: $timing_function
228
+ -moz-transition-timing-function: $timing_function
229
+ -o-transition-timing-function: $timing_function
230
+ transition-timing-function: $timing_function
231
+
232
+ @mixin backface-visibility($what)
233
+ backface-visibility: $what
234
+ -moz-backface-visibility: $what
235
+ -webkit-backface-visibility: $what
236
+
237
+
238
+ /* TRIPLE BORDERS */
239
+ @mixin triple-borders($colorOne: #3C3C3C, $colorTwo: #999999, $colorThree: #000000, $radius: 0)
240
+ border: 1px solid $colorOne
241
+
242
+ @include border-radius($radius)
243
+
244
+ -webkit-box-shadow: 0 0 0 1px $colorTwo, 0 0 0 2px $colorThree
245
+ -moz-box-shadow: 0 0 0 1px $colorTwo, 0 0 0 2px $colorThree
246
+ box-shadow: 0 0 0 1px $colorTwo, 0 0 0 2px $colorThree
247
+
248
+ @mixin filter($what)
249
+ filter: $what
250
+ -moz-filter: $what
251
+ -webkit-filter: $what
252
+
253
+ @mixin perspective($value)
254
+ perspective: $value
255
+ -moz-perspective: $value
256
+ -webkit-perspective: $value
257
+
258
+ @mixin transform-style($value)
259
+ transform-style: $value
260
+ -moz-transform-style: $value
261
+ -webkit-transform-style: $value
262
+
263
+ @mixin gradient-vertical-three-colors-no-filter($start-color, $mid-color, $color-stop, $end-color)
264
+ background-image: -webkit-linear-gradient($start-color, $mid-color $color-stop, $end-color)
265
+ background-image: linear-gradient($start-color, $mid-color $color-stop, $end-color)
266
+ background-repeat: no-repeat
@@ -0,0 +1,28 @@
1
+ # Assignment:
2
+ number = 42
3
+ opposite = true
4
+
5
+ # Conditions:
6
+ number = -42 if opposite
7
+
8
+ # Functions:
9
+ square = (x) -> x * x
10
+
11
+ # Arrays:
12
+ list = [1, 2, 3, 4, 5]
13
+
14
+ # Objects:
15
+ math =
16
+ root: Math.sqrt
17
+ square: square
18
+ cube: (x) -> x * square x
19
+
20
+ # Splats:
21
+ race = (winner, runners...) ->
22
+ print winner, runners
23
+
24
+ # Existence:
25
+ alert "I knew it!" if elvis?
26
+
27
+ # Array comprehensions:
28
+ cubes = (math.cube num for num in list)
@@ -0,0 +1,5 @@
1
+ module TestHelper
2
+ def testhelper_method
3
+ 'testhelper_method'
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ %h1.test1
2
+ headline
3
+
4
+ %p
5
+ Here is the index page content.
6
+ %p
7
+ And more index content.
8
+
9
+ %p
10
+ this comes from shared/shared_helper.rb:
11
+ = sharedhelper_method
12
+
13
+ %p
14
+ this comes from test1/test_helper.rb:
15
+ = testhelper_method
@@ -0,0 +1,10 @@
1
+ !!!
2
+ %html{lang: 'de'}
3
+ %head
4
+ = render_partial '_metadata'
5
+ = render_partial '_assets'
6
+
7
+ %body{class: body_class}
8
+ = render_partial '_header'
9
+ = yield
10
+ = render_partial '_footer'
@@ -0,0 +1,11 @@
1
+ = link_tag 'favicon.ico', 'icon', 'image/x-icon'
2
+ = link_tag 'favicon.ico', 'shortcut icon', 'image/x-icon'
3
+ = stylesheet_link_tag 'http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css'
4
+ = stylesheet_link_tag 'main.css'
5
+ = javascript_include_tag 'https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'
6
+ = javascript_include_tag 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js'
7
+ /[if lt IE 9]
8
+ = javascript_include_tag 'https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js'
9
+ = javascript_include_tag 'https://oss.maxcdn.com/respond/1.4.2/respond.min.js'
10
+ %script
11
+ var ltie9 = true
@@ -0,0 +1 @@
1
+ FOOTER
@@ -0,0 +1 @@
1
+ HEADER
@@ -0,0 +1,9 @@
1
+ %title
2
+ test 1
3
+
4
+ = meta_tag_http 'Content-Type', 'text/html; charset=utf-8'
5
+ = meta_tag_http 'X-UA-Compatible', 'IE=edge'
6
+ = meta_tag 'robots', 'noindex,follow,noodp,noydir'
7
+ = meta_tag 'description', ''
8
+ = meta_tag 'keywords', ''
9
+ = meta_tag 'viewport', 'width=device-width, initial-scale=1.0'
File without changes
@@ -0,0 +1,3 @@
1
+ h1
2
+ .test1
3
+ font-size: 20px
@@ -0,0 +1,28 @@
1
+ # Assignment:
2
+ number = 42
3
+ opposite = true
4
+
5
+ # Conditions:
6
+ number = -42 if opposite
7
+
8
+ # Functions:
9
+ square = (x) -> x * x
10
+
11
+ # Arrays:
12
+ list = [1, 2, 3, 4, 5]
13
+
14
+ # Objects:
15
+ math =
16
+ root: Math.sqrt
17
+ square: square
18
+ cube: (x) -> x * square x
19
+
20
+ # Splats:
21
+ race = (winner, runners...) ->
22
+ print winner, runners
23
+
24
+ # Existence:
25
+ alert "I knew it!" if elvis?
26
+
27
+ # Array comprehensions:
28
+ cubes = (math.cube num for num in list)
@@ -0,0 +1,4 @@
1
+ %p
2
+ Here is the index page content.
3
+ %p
4
+ And more index content.
@@ -0,0 +1,7 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title
5
+ = render_partial :title
6
+ %body
7
+ = yield
@@ -0,0 +1 @@
1
+ Default Page Title
@@ -0,0 +1,3 @@
1
+ h2
2
+ .test2
3
+ font-size: 20px
@@ -0,0 +1,6 @@
1
+ require_relative 'server/server.rb'
2
+ require_relative 'server/dispatcher.rb'
3
+
4
+ server = Server::Server.new Server::Dispatcher.new
5
+
6
+ server.listen 5678
@@ -0,0 +1,26 @@
1
+ require 'fileutils'
2
+ require 'coffee-script'
3
+
4
+ module Generator
5
+ class CoffeeGenerator
6
+ def generate input_folder, output_folder
7
+ Dir.glob("#{input_folder}/*.coffee").select do |file|
8
+ next unless File.file? file
9
+
10
+ result = compile(file)
11
+ file_name = file.split('/')[-1].gsub('.coffee', '.js')
12
+ write File.join(output_folder, file_name), result
13
+ end
14
+ end
15
+
16
+ def compile file
17
+ CoffeeScript.compile(File.read(file))
18
+ end
19
+
20
+ def write file, content
21
+ File.open(file, "w") do |f|
22
+ f.write content
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,52 @@
1
+ require_relative 'sass_generator.rb'
2
+ require_relative 'coffee_generator.rb'
3
+ require_relative 'haml_generator.rb'
4
+ require_relative 'structure_generator.rb'
5
+
6
+ module Generator
7
+ class Generator
8
+ def initialize
9
+ @haml = HamlGenerator.new
10
+ @sass = SassGenerator.new
11
+ @coffee = CoffeeGenerator.new
12
+ @structure = StructureGenerator.new
13
+ end
14
+
15
+ def web_root
16
+ return 'web_root/'
17
+ end
18
+
19
+ def dev_root
20
+ return 'dev_root/'
21
+ end
22
+
23
+ def projects_folder
24
+ Dir.glob("#{dev_root}/*")
25
+ end
26
+
27
+ def project_name project_folder
28
+ project_folder.split('/')[-1]
29
+ end
30
+
31
+ def project_web_folder project
32
+ "#{web_root}/#{project}"
33
+ end
34
+
35
+ def generate
36
+ FileUtils.rm_rf(Dir.glob("web_root/*"))
37
+
38
+ projects_folder.each do |project_folder|
39
+ next unless File.directory? project_folder
40
+ next if project_folder.include? 'shared'
41
+
42
+ project_name = project_folder.split('/')[-1]
43
+ project_output_folder = project_web_folder(project_name)
44
+
45
+ @structure.generate project_folder, project_output_folder
46
+ @haml.generate project_folder, project_output_folder
47
+ @coffee.generate "#{project_folder}/coffee", "#{project_output_folder}/js"
48
+ @sass.generate "#{project_folder}/sass" , "#{project_output_folder}/css"
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,99 @@
1
+ require 'fileutils'
2
+ require 'haml'
3
+ require 'action_view'
4
+
5
+ #require shared helper
6
+ $shared_helper = Dir.glob('./dev_root/shared/helper/*.rb')
7
+ $shared_helper.each do |file| require file end
8
+
9
+ module Generator
10
+ class HamlGenerator
11
+ def initialize()
12
+ @example_boolean = false
13
+ @haml_options = { attr_wrapper: '"', format: :html5 }
14
+ end
15
+
16
+ def generate input_folder, output_folder
17
+ layout = "#{input_folder}/layout.haml"
18
+
19
+ Dir.glob("#{input_folder}/*.haml").select do |file|
20
+ next unless File.file? file and !file.include? 'layout.haml'
21
+
22
+ result = compile(file, layout, input_folder, output_folder)
23
+ file_name = file.split('/')[-1].gsub('.haml', '.html')
24
+ write File.join(output_folder, file_name), result
25
+ end
26
+ end
27
+
28
+ def compile file, layout, input_folder, output_folder
29
+ scope = file.split('/')[-1].split('.').first
30
+ layout = Haml::Engine.new(File.read(layout), @haml_options)
31
+ c = Context.new @example_boolean, scope, @haml_options, input_folder, output_folder
32
+
33
+ # If the file being processed by Haml contains a yield statement, the block passed to
34
+ # "render" will be called when it's hit.
35
+ layout.render c, body_class: scope do
36
+ # Render the actual page contents in place of the call to "yield".
37
+ body = Haml::Engine.new(File.read(file), @haml_options)
38
+ body.render(c)
39
+ end
40
+ end
41
+
42
+ def write file, content
43
+ File.open(file, "w") do |f|
44
+ f.write content
45
+ end
46
+ end
47
+ end
48
+
49
+ # Calls to "render" can take a context object that will be accessible from the templates.
50
+ class Context
51
+ # Any properties of this object are available in the Haml templates.
52
+ attr_reader :example_boolean
53
+
54
+ include ActionView::Helpers
55
+
56
+ $shared_helper.each do |path|
57
+ file_without_ext = path.split('/')[-1].split('.').first
58
+ module_name = file_without_ext.classify
59
+ STDERR.puts 'loading helper -> '+module_name
60
+ include module_name.constantize
61
+ end
62
+
63
+ def initialize(example_boolean, scope, options, input_folder, output_folder)
64
+ @example_boolean = example_boolean
65
+ @scope = scope
66
+ @options = options
67
+ @input_folder = input_folder
68
+ @output_folder = output_folder
69
+ Dir.glob("./#{input_folder}/helper/*.rb").each do |path|
70
+ require path
71
+ file_without_ext = path.split('/')[-1].split('.').first
72
+ module_name = file_without_ext.classify
73
+ STDERR.puts 'loading project helper -> '+module_name
74
+ self.class.send(:include, module_name.constantize)
75
+ end
76
+ end
77
+
78
+ # This function is no different from the "copyright_year" function above. It just uses some
79
+ # conventions to render another template file when it's called.
80
+ def render_partial(file_name)
81
+ # The "default" version of the partial.
82
+ file_to_render = "#{@input_folder}/partials/#{file_name.to_s}.haml"
83
+ if @scope
84
+ # Look for a partial prefixed with the current "scope" (which is just the name of the
85
+ # primary template being rendered).
86
+ scope_file = "#{@input_folder}/partials/#{@scope.to_s}_#{file_name.to_s}.haml"
87
+ # Use it if it's there.
88
+ file_to_render = scope_file if File.exists? scope_file
89
+ end
90
+ # If we found a matching partial (either the scoped one or the default), render it now.
91
+ if File.exists? file_to_render
92
+ partial = Haml::Engine.new(File.read(file_to_render), @options)
93
+ partial.render self
94
+ else
95
+ nil
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,31 @@
1
+ require 'fileutils'
2
+ require 'sass'
3
+
4
+ #just require bootsrap and it will be in the sass path
5
+ require 'bootstrap-sass'
6
+
7
+ module Generator
8
+ class SassGenerator
9
+ def generate input_folder, output_folder
10
+ Dir.glob("#{input_folder}/*.sass").select do |file|
11
+ file_name = file.split('/')[-1]
12
+ next unless File.file? file and file_name[0] != '_'
13
+
14
+ result = compile(file)
15
+ file_name = file.split('/')[-1].gsub('.sass', '.css')
16
+ write File.join(output_folder, file_name), result
17
+ end
18
+ end
19
+
20
+ def compile file
21
+ engine = Sass::Engine.new(File.read(file))
22
+ engine.render
23
+ end
24
+
25
+ def write file, content
26
+ File.open(file, "w") do |f|
27
+ f.write content
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ require 'fileutils'
2
+
3
+ module Generator
4
+ class StructureGenerator
5
+ def generate input_folder, output_folder
6
+ return if File.directory? output_folder
7
+
8
+ FileUtils::mkdir_p output_folder
9
+ copy_public_content(input_folder, output_folder)
10
+ FileUtils::mkdir_p "#{output_folder}/css/"
11
+ FileUtils::mkdir_p "#{output_folder}/js/"
12
+ end
13
+
14
+ def copy_public_content input_folder, output_folder
15
+ src_dir = "#{input_folder}/public"
16
+ return unless File.directory? src_dir
17
+
18
+ FileUtils::copy_entry(src_dir, output_folder)
19
+ end
20
+ end
21
+ end
22
+
23
+
24
+
@@ -0,0 +1,52 @@
1
+ require_relative '../generator/generator.rb'
2
+
3
+ module Server
4
+ class Dispatcher
5
+ WEB_ROOT = 'web_root'
6
+
7
+ def execute_php(path, params)
8
+ params_s = ''
9
+ params.each do |key, value|
10
+ params_s+=key+'='+value[0]+' '
11
+ end
12
+ executors = ['php', 'php-cgi', 'php-fpm']
13
+ cmd = "#{executors[0]} #{path} #{params_s}"
14
+ STDERR.puts(cmd)
15
+ %x[ #{cmd} ]
16
+ end
17
+
18
+ def regenerate_files_if(path, server)
19
+ return unless path.include? '.html'
20
+
21
+ #no html? no reload -> no regenarate
22
+ server.log "Renew all files"
23
+ Generator::Generator.new.generate
24
+ end
25
+
26
+ def dispatch(request, response, server)
27
+ path = request.path
28
+ server.log path
29
+
30
+ regenerate_files_if(path, server)
31
+
32
+ # Make sure the file exists and is not a directory
33
+ # before attempting to open it.
34
+ if File.exist?(path) && !File.directory?(path)
35
+ if path.include? '.php'
36
+ response.send(200, execute_php(path, request.params))
37
+ else
38
+ response.send_file path
39
+ end
40
+ elsif File.exist?(path) && File.directory?(path)
41
+ path = "#{path}/index.html"
42
+ if File.exist?(path) && !File.directory?(path)
43
+ response.send_301 path
44
+ else
45
+ response.send_404
46
+ end
47
+ else
48
+ response.send_404
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,51 @@
1
+ require 'uri'
2
+
3
+ module Server
4
+ class Request
5
+ attr_reader :request, :socket
6
+
7
+ def initialize(socket)
8
+ @request = socket.gets
9
+ @socket = socket
10
+ end
11
+
12
+ def uri
13
+ @request.split(" ")[1]
14
+ end
15
+
16
+ def params
17
+ @params ||= CGI::parse(URI(uri).query)
18
+ end
19
+
20
+ def path
21
+ clean = []
22
+
23
+ # Split the path into components
24
+ parts = original_path.split("/")
25
+
26
+ parts.each do |part|
27
+ # skip any empty or current directory (".") path components
28
+ next if part.empty? || part == '.'
29
+ # If the path component goes up one directory level (".."),
30
+ # remove the last clean component.
31
+ # Otherwise, add the component to the Array of clean components
32
+ part == '..' ? clean.pop : clean << part
33
+ end
34
+
35
+ # return the web root joined to the clean path
36
+ File.join(Dispatcher::WEB_ROOT, *clean)
37
+ end
38
+
39
+ def original_path
40
+ URI.unescape(URI(uri).path)
41
+ end
42
+
43
+ def to_s
44
+ @request
45
+ end
46
+
47
+ def empty?
48
+ return @request ? false : true
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,82 @@
1
+ module Server
2
+ # Map extensions to their content type
3
+ CONTENT_TYPE_MAPPING = {
4
+ 'html' => 'text/html',
5
+ 'txt' => 'text/plain',
6
+ 'png' => 'image/png',
7
+ 'jpg' => 'image/jpeg',
8
+ 'ico' => 'image/x-icon',
9
+ 'js' => 'text/javascript',
10
+ 'css' => 'text/css',
11
+ 'php' => 'text/html'
12
+ }
13
+
14
+ # Treat as binary data if content type cannot be found
15
+ DEFAULT_CONTENT_TYPE = 'application/octet-stream'
16
+
17
+ # This helper function parses the extension of the
18
+ # requested file and then looks up its content type.
19
+
20
+ class Response
21
+ def initialize(request, server)
22
+ @request = request
23
+ @socket = request.socket
24
+ @server = server
25
+ end
26
+
27
+ def log msg
28
+ @server.log msg
29
+ end
30
+
31
+ def print msg
32
+ @socket.print msg
33
+ end
34
+
35
+ def send_404
36
+ code = 404
37
+ message = "404: File '#{@request.path}' not found\n"
38
+ log "404: File not found #{@request.path}"
39
+
40
+ send(code, message)
41
+ end
42
+
43
+ def content_type file
44
+ ext = File.extname(file).split(".").last
45
+ CONTENT_TYPE_MAPPING.fetch(ext, DEFAULT_CONTENT_TYPE)
46
+ end
47
+
48
+ def send_301 redirect_to
49
+ redirect_to.slice!("web_root")
50
+ redirect_to = "http://#{@socket.addr[2]}:#{@socket.addr[1]}#{redirect_to}"
51
+
52
+ log "301: redirect to #{redirect_to}"
53
+
54
+ # respond with a 301 error code to redirect
55
+ print "HTTP/1.1 301 Moved Permanently\r\n" +
56
+ "Location: #{redirect_to}\r\n"+
57
+ "Connection: close\r\n"
58
+ end
59
+
60
+ def send_file path
61
+ File.open(@request.path, "rb") do |file|
62
+ print "HTTP/1.1 200 OK\r\n" +
63
+ "Content-Type: #{content_type(file)}\r\n" +
64
+ "Content-Length: #{file.size}\r\n" +
65
+ "Connection: close\r\n" +
66
+ "\r\n"
67
+
68
+ # write the contents of the file to the socket
69
+ IO.copy_stream(file, @socket)
70
+ end
71
+ end
72
+
73
+ def send(code, message)
74
+ print "HTTP/1.1 #{code} Not Found\r\n" +
75
+ "Content-Type: text/plain\r\n" +
76
+ "Content-Length: #{message.size}\r\n" +
77
+ "Connection: close\r\n" +
78
+ "\r\n" +
79
+ message
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,42 @@
1
+ require 'socket'
2
+
3
+ require_relative 'request.rb'
4
+ require_relative 'response.rb'
5
+
6
+ module Server
7
+ class Server
8
+ def initialize(dispatcher)
9
+ @dispatcher = dispatcher
10
+ end
11
+
12
+ def listen(port, host='127.0.0.1')
13
+ server = TCPServer.new(host, port)
14
+ log "Server binded to http://#{host}:#{port}"
15
+
16
+ loop do
17
+ socket = server.accept
18
+ request = Request.new socket
19
+ response = Response.new request, self
20
+
21
+ log request
22
+ next if request.empty?
23
+
24
+ begin
25
+ @dispatcher.dispatch(request, response, self)
26
+ rescue Exception => e
27
+ msg = "#{e.backtrace.first}: #{e.message} (#{e.class})", e.backtrace.drop(1).map{|s| "\t#{s}"}
28
+ socket.print '<pre style="max-width: 100%; color: red; width: 100%; font-size:20px; white-space: normal;">'
29
+ socket.print msg
30
+ socket.print '</pre>'
31
+ log msg
32
+ end
33
+
34
+ socket.close
35
+ end
36
+ end
37
+
38
+ def log msg
39
+ STDERR.puts msg
40
+ end
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy_html_creator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tom Hanolt
9
+ - Dennis van de Hoef
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-11-09 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: haml
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: sass
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: coffee-script
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rake
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: bootstrap-sass
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :runtime
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: actionview
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: ! 'Easy_html_creator is a gem that makes developing static HTML websites
112
+ easy and joyful.
113
+
114
+
115
+ Once you learned the joy of haml or sass, it get boring to program in ''plain old''
116
+ html and css.
117
+
118
+
119
+ Using our Gem you could generate and maintain multiple static websites and program
120
+ them in your preferred languages.
121
+
122
+
123
+ Currently supported by our fast and lightweight re-generation server:
124
+
125
+ HAML
126
+
127
+ Sass (with bootstarp)
128
+
129
+ CoffeeScript
130
+
131
+
132
+ We also included the ''actionview'' gem, to enable the use of rails standard functions
133
+ like ''text_field_tag''.'
134
+ email:
135
+ executables:
136
+ - startServer
137
+ - generateFiles
138
+ - initDevRoot
139
+ extensions: []
140
+ extra_rdoc_files: []
141
+ files:
142
+ - bin/generateFiles
143
+ - bin/initDevRoot
144
+ - bin/startServer
145
+ - lib/server/server.rb
146
+ - lib/server/response.rb
147
+ - lib/server/dispatcher.rb
148
+ - lib/server/request.rb
149
+ - lib/easy_html_creator.rb
150
+ - lib/generator/sass_generator.rb
151
+ - lib/generator/structure_generator.rb
152
+ - lib/generator/generator.rb
153
+ - lib/generator/haml_generator.rb
154
+ - lib/generator/coffee_generator.rb
155
+ - dev_root/test2/layout.haml
156
+ - dev_root/test2/coffee/test.coffee
157
+ - dev_root/test2/partials/title.haml
158
+ - dev_root/test2/sass/test.sass
159
+ - dev_root/test2/index.haml
160
+ - dev_root/test1/layout.haml
161
+ - dev_root/test1/coffee/test.coffee
162
+ - dev_root/test1/partials/_metadata.haml
163
+ - dev_root/test1/partials/_assets.haml
164
+ - dev_root/test1/partials/_footer.haml
165
+ - dev_root/test1/partials/_header.haml
166
+ - dev_root/test1/sass/main.sass
167
+ - dev_root/test1/helper/test_helper.rb
168
+ - dev_root/test1/public/robots.txt
169
+ - dev_root/test1/index.haml
170
+ - dev_root/shared/sass/_css3.sass
171
+ - dev_root/shared/helper/activesupport_override.rb
172
+ - dev_root/shared/helper/shared_helper.rb
173
+ - LICENSE
174
+ - README.md
175
+ - Gemfile
176
+ - CHANGELOG.md
177
+ homepage: https://github.com/dennisvandehoef/easy-html-creator
178
+ licenses:
179
+ - MIT
180
+ post_install_message:
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ none: false
192
+ requirements:
193
+ - - ! '>='
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ requirements: []
197
+ rubyforge_project:
198
+ rubygems_version: 1.8.23
199
+ signing_key:
200
+ specification_version: 3
201
+ summary: A simple project for fast and easy HTML website createmend
202
+ test_files: []