easy_html_generator 1.0.4 → 1.0.5
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.
- checksums.yaml +4 -4
- data/.codeclimate.yml +6 -0
- data/.gitignore +12 -0
- data/.rubocop.yml +18 -0
- data/.travis.yml +14 -0
- data/Gemfile +3 -0
- data/README.md +51 -337
- data/Rakefile +42 -0
- data/config.ru +4 -0
- data/docs/CONFIGURATION.md +84 -0
- data/{CONTRIBUTING.md → docs/CONTRIBUTING.md} +2 -0
- data/docs/GENERATORS.md +210 -0
- data/docs/GETSTARTED.md +92 -0
- data/easy_html_generator.gemspec +54 -0
- data/lib/easy_html_generator/checksum.rb +4 -0
- data/lib/easy_html_generator/config.rb +0 -77
- data/lib/easy_html_generator/generator/base.rb +20 -58
- data/lib/easy_html_generator/generator/combine.rb +9 -19
- data/lib/easy_html_generator/generator/compile/base.rb +51 -0
- data/lib/easy_html_generator/generator/compile/coffee.rb +6 -13
- data/lib/easy_html_generator/generator/compile/haml/helper/activesupport_override.rb +1 -6
- data/lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb +7 -7
- data/lib/easy_html_generator/generator/compile/haml.rb +20 -45
- data/lib/easy_html_generator/generator/compile/sass.rb +9 -13
- data/lib/easy_html_generator/generator/copy.rb +7 -14
- data/lib/easy_html_generator/generator/delete.rb +4 -13
- data/lib/easy_html_generator/generator/minimize/css.rb +5 -12
- data/lib/easy_html_generator/generator/minimize/html.rb +5 -12
- data/lib/easy_html_generator/generator/minimize/images.rb +6 -20
- data/lib/easy_html_generator/generator/minimize/js.rb +5 -12
- data/lib/easy_html_generator/generator/service/analytics.rb +19 -19
- data/lib/easy_html_generator/generator/service/bower.rb +21 -17
- data/lib/easy_html_generator/generator/service/grunt.rb +12 -11
- data/lib/easy_html_generator/generator/service/sitemap.rb +33 -0
- data/lib/easy_html_generator/generator/structure.rb +2 -6
- data/lib/easy_html_generator/generator.rb +6 -6
- data/lib/easy_html_generator/project.rb +5 -0
- data/lib/easy_html_generator/project_path_resolver.rb +57 -0
- data/lib/easy_html_generator/rack_dispatcher.rb +1 -1
- data/lib/easy_html_generator/version.rb +4 -0
- data/lib/easy_html_generator/workspace.rb +1 -1
- data/lib/easy_html_generator.rb +19 -18
- data/src/demo/assets/styles/app.css.sass +47 -2
- data/src/demo/lib/helper/projecthelper.rb +3 -0
- data/src/demo/project.yml +142 -0
- data/src/demo/views/index/_bower_and_grunt.haml +7 -0
- data/src/demo/views/index/_dry.haml +16 -0
- data/src/demo/views/index/_haml_sass_coffee.haml +11 -0
- data/src/demo/views/index/_inline_coffee_and_sass.haml +43 -0
- data/src/demo/views/index/_sass_mixins.haml +76 -0
- data/src/demo/views/index.html.haml +13 -1
- data/src/demo/views/layout/_assets.javascripts.haml +7 -0
- data/src/demo/views/layout/_assets.metadata.haml +12 -0
- data/src/demo/views/layout/_assets.stylesheets.haml +9 -0
- data/src/demo/views/layout/_footer.haml +3 -0
- data/src/demo/views/layout/_header.haml +1 -0
- data/src/demo/views/layout.haml +8 -4
- data/src/demo/views/plain.html +1 -0
- data/src/shared/assets/styles/mixins/_bootstrap-fixes.sass +12 -0
- data/src/shared/assets/styles/mixins/_headjs-bootstrap-mediaqueries.sass +30 -0
- data/src/shared/project.yml +56 -35
- data/src/template/project.yml +57 -43
- metadata +75 -7
- data/src/demo/views/index/_lore_ipsum.haml +0 -1
data/docs/GENERATORS.md
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
# Basic-Generators
|
2
|
+
### Structure
|
3
|
+
* creates necessary dist folders
|
4
|
+
|
5
|
+
```
|
6
|
+
- structure:
|
7
|
+
enabled: true
|
8
|
+
```
|
9
|
+
|
10
|
+
### Copy
|
11
|
+
* copies folder or files
|
12
|
+
* `selector` is optional, default selector: `**/*`
|
13
|
+
|
14
|
+
```
|
15
|
+
- copy:
|
16
|
+
enabled: true
|
17
|
+
repetitive:
|
18
|
+
-
|
19
|
+
source: 'src.styles://'
|
20
|
+
target: 'dist.styles://'
|
21
|
+
selector: '**/*.css'
|
22
|
+
-
|
23
|
+
source: 'src://assets/scripts'
|
24
|
+
target: 'dist://scripts'
|
25
|
+
selector: '**/*.js'
|
26
|
+
```
|
27
|
+
|
28
|
+
### Combine
|
29
|
+
* combines multiple files
|
30
|
+
|
31
|
+
```
|
32
|
+
- combine:
|
33
|
+
enabled: true
|
34
|
+
repetitive:
|
35
|
+
-
|
36
|
+
target: 'dist.scripts://app.combined.js'
|
37
|
+
sources:
|
38
|
+
- 'dist.scripts://*.js'
|
39
|
+
```
|
40
|
+
|
41
|
+
### Delete
|
42
|
+
* deletes files or folders
|
43
|
+
|
44
|
+
```
|
45
|
+
- delete:
|
46
|
+
enabled: false
|
47
|
+
source: 'dist://**/*'
|
48
|
+
```
|
49
|
+
|
50
|
+
# Compile-Generators
|
51
|
+
### Compile::Haml
|
52
|
+
* compiles haml files to html files
|
53
|
+
* supports partials and minimizing
|
54
|
+
* supports [ActionView](https://github.com/rails/rails/tree/master/actionview) syntax and view helper
|
55
|
+
* supports layouts, the layout can bespezified in the first line of a haml file with `-# ehg layout: layout.blank`, default layout is `my_project/views/layout.haml`
|
56
|
+
|
57
|
+
```
|
58
|
+
- compile_haml:
|
59
|
+
enabled: true
|
60
|
+
minimize: true
|
61
|
+
source: 'src.views://'
|
62
|
+
target: 'dist.views://'
|
63
|
+
selector: '**/*.html.haml'
|
64
|
+
default_layout: 'views/layout.haml'
|
65
|
+
renderer:
|
66
|
+
attr_wrapper: '"'
|
67
|
+
format: :html5
|
68
|
+
shared_helper_path: 'shared/lib'
|
69
|
+
```
|
70
|
+
|
71
|
+
### Compile::Sass
|
72
|
+
* compiles sass files to css files
|
73
|
+
* supports shared mixins and minimizing
|
74
|
+
|
75
|
+
```
|
76
|
+
- compile_sass:
|
77
|
+
enabled: true
|
78
|
+
minimize: true
|
79
|
+
source: 'src.styles://'
|
80
|
+
target: 'dist.styles://'
|
81
|
+
selector: '**/*.css.sass'
|
82
|
+
```
|
83
|
+
|
84
|
+
### Compile::Coffee
|
85
|
+
* compiles coffee files to js files
|
86
|
+
* supports minimizing
|
87
|
+
|
88
|
+
```
|
89
|
+
- compile_coffee:
|
90
|
+
enabled: true
|
91
|
+
minimize: true
|
92
|
+
source: 'src.scripts://'
|
93
|
+
target: 'dist.scripts://'
|
94
|
+
selector: '**/*.js.coffee'
|
95
|
+
```
|
96
|
+
|
97
|
+
# Minimize-Generators
|
98
|
+
### Minimize::Html
|
99
|
+
* minimizes html files and copies to `target`
|
100
|
+
* `prefix_extension='.min'` stores athe minimized content from `foo.html` to `foo.min.html`
|
101
|
+
|
102
|
+
```
|
103
|
+
- minimize_html:
|
104
|
+
enabled: true
|
105
|
+
source: 'src.public://'
|
106
|
+
target: 'dist.public://'
|
107
|
+
selector: '**/*.html'
|
108
|
+
prefix_extension: ''
|
109
|
+
```
|
110
|
+
|
111
|
+
### Minimize::Css
|
112
|
+
* minimizes css files and copies to `target`
|
113
|
+
|
114
|
+
```
|
115
|
+
- minimize_css:
|
116
|
+
enabled: true
|
117
|
+
source: 'src.styles://'
|
118
|
+
target: 'dist.styles://'
|
119
|
+
selector: '**/*.css'
|
120
|
+
prefix_extension: '.min'
|
121
|
+
```
|
122
|
+
|
123
|
+
#### Minimize::Js
|
124
|
+
* minimizes js files and copies to `target`
|
125
|
+
|
126
|
+
```
|
127
|
+
- minimize_js:
|
128
|
+
enabled: true
|
129
|
+
source: 'src.scripts://'
|
130
|
+
target: 'dist.scripts://'
|
131
|
+
selector: '**/*.js'
|
132
|
+
prefix_extension: '.min'
|
133
|
+
```
|
134
|
+
|
135
|
+
### Minimize::Images
|
136
|
+
* minimizes image files and copies to `target`
|
137
|
+
* uses [Piet](https://github.com/albertbellonch/piet) for image processing
|
138
|
+
|
139
|
+
```
|
140
|
+
- minimize_images:
|
141
|
+
enabled: true
|
142
|
+
source: 'src.images://'
|
143
|
+
target: 'dist.images://'
|
144
|
+
selector: '**/*.{jpg,png}'
|
145
|
+
options:
|
146
|
+
quality: 90
|
147
|
+
level: 3
|
148
|
+
verbose: true
|
149
|
+
```
|
150
|
+
|
151
|
+
## Service-Generators
|
152
|
+
#### Service::Bower
|
153
|
+
* resolves `src://bower.json` and copies bower_components to target folder
|
154
|
+
|
155
|
+
```
|
156
|
+
- service_bower:
|
157
|
+
enabled: true
|
158
|
+
source: 'src://'
|
159
|
+
target: 'dist://lib'
|
160
|
+
```
|
161
|
+
|
162
|
+
### Service::Grunt
|
163
|
+
* resolves `src://Gruntfile.coffee` and runs a `task`
|
164
|
+
|
165
|
+
```
|
166
|
+
- service_grunt:
|
167
|
+
enabled: false
|
168
|
+
source: 'src://Gruntfile.coffee'
|
169
|
+
task: 'default'
|
170
|
+
```
|
171
|
+
|
172
|
+
### Service::Analytics
|
173
|
+
* appends tracking codes to the end of head tag to selected html files
|
174
|
+
|
175
|
+
```
|
176
|
+
- service_analytics:
|
177
|
+
enabled: true
|
178
|
+
source: 'dist.views://'
|
179
|
+
target: 'dist.views://'
|
180
|
+
selector: '*.html'
|
181
|
+
repetitive:
|
182
|
+
-
|
183
|
+
enabled: true
|
184
|
+
name: 'google'
|
185
|
+
code: "<script>[...] _gaq.push(['_setAccount', '{GOOGLE_UA_ID}']); [...]</script>"
|
186
|
+
params:
|
187
|
+
GOOGLE_UA_ID: 'UA-65996211-1'
|
188
|
+
```
|
189
|
+
### Service::Sitemap
|
190
|
+
* generates a sitemap xml file based on selected files
|
191
|
+
* `blacklist` can be used to exclude files
|
192
|
+
|
193
|
+
```
|
194
|
+
- service_sitemap:
|
195
|
+
domain: 'beta.creative-workflow.berlin'
|
196
|
+
enabled: true
|
197
|
+
source: 'dist.views://*.html'
|
198
|
+
target: 'dist.views://sitemap.xml'
|
199
|
+
selector: '**/*.html'
|
200
|
+
blacklist:
|
201
|
+
```
|
202
|
+
|
203
|
+
|
204
|
+
# Resources
|
205
|
+
|
206
|
+
> "[Getting started](https://github.com/creative-workflow/easy-html-generator/blob/master/docs/GETSTARTED.md)"
|
207
|
+
|
208
|
+
> "[Configuration](https://github.com/creative-workflow/easy-html-generator/blob/master/docs/CONFIGURATION.md)"
|
209
|
+
|
210
|
+
>"[Contributing](https://github.com/creative-workflow/easy-html-generator/blob/master/docs/CONTRIBUTING.md)"
|
data/docs/GETSTARTED.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# Get started
|
2
|
+
At first you need [Ruby](https://www.ruby-lang.org/de/) and [Bundler](http://bundler.io/).
|
3
|
+
|
4
|
+
For specific generators install:
|
5
|
+
* [OptiPng](http://optipng.sourceforge.net/) for png image minimizing
|
6
|
+
* [JpegOptim](https://github.com/tjko/jpegoptim) for jpg image minimizing
|
7
|
+
* [NodeJs](https://nodejs.org/download/) to use bower and grunt https://www.npmjs.com/
|
8
|
+
* [Bower](http://bower.io/) to use bower `npm install -g bower`
|
9
|
+
* [Grunt](http://gruntjs.com/getting-started) to use grunt `npm install -g grunt-cli`
|
10
|
+
|
11
|
+
Create a new workspace folder
|
12
|
+
|
13
|
+
mkdir my_workspace
|
14
|
+
cd my_workspace
|
15
|
+
|
16
|
+
Create a ruby `Gemfile`
|
17
|
+
|
18
|
+
touch Gemfile
|
19
|
+
|
20
|
+
Paste this into the `Gemfile`
|
21
|
+
|
22
|
+
source 'https://rubygems.org'
|
23
|
+
|
24
|
+
gem 'easy_html_generator'
|
25
|
+
|
26
|
+
For the latest development version use
|
27
|
+
|
28
|
+
gem 'easy_html_generator', git: 'git@github.com:creative-workflow/easy-html-generator.git', branch: 'development-master'
|
29
|
+
|
30
|
+
Run in terminal
|
31
|
+
|
32
|
+
bundle install
|
33
|
+
ehg --init
|
34
|
+
ehg --create my_project
|
35
|
+
|
36
|
+
Now you should see the following folder structure with `ls -alR`
|
37
|
+
|
38
|
+
my_workspace
|
39
|
+
├── dist # the generated result will be stored here
|
40
|
+
└── src # the generation input is stored here
|
41
|
+
├── demo
|
42
|
+
├── my_project # this is a project and will be available via http://localhost:9292/my_project
|
43
|
+
│ ├── assets
|
44
|
+
│ │ ├── images # content will be copied to `dist/my_project/images`
|
45
|
+
│ │ ├── public # public content gets directly copied to `dist/my_project/`
|
46
|
+
│ │ ├── scripts # content will be copied to `dist/my_project/scripts`
|
47
|
+
│ │ └── styles # content will be copied to `dist/my_project/styles`
|
48
|
+
│ ├── lib
|
49
|
+
│ │ ├── generators # project specific generators
|
50
|
+
│ │ └── helper # project specific view helpers you can use in haml files
|
51
|
+
│ ├── project.yml # project specific generators config
|
52
|
+
│ └── views
|
53
|
+
│ ├── index.html.haml # the haml file for index.html
|
54
|
+
│ └── layout.haml # the layout file index.html will use
|
55
|
+
|
|
56
|
+
└── shared # shared content over all projects
|
57
|
+
├── assets # shared assets over all projects
|
58
|
+
│ ├── images
|
59
|
+
│ ├── public
|
60
|
+
│ ├── scripts
|
61
|
+
│ └── styles
|
62
|
+
│ └── mixins # here are css helpers for bootstrap and head js
|
63
|
+
├── lib
|
64
|
+
│ ├── generators # generators shared over all projects
|
65
|
+
│ └── helper # view helpers you can use in haml files
|
66
|
+
└── project.yml # if a project doesnt have a `project.yml` this config will be used
|
67
|
+
|
68
|
+
Now run
|
69
|
+
|
70
|
+
ehg --server
|
71
|
+
|
72
|
+
...and navigate your web browser to `http://localhost:9292`
|
73
|
+
|
74
|
+
After a short time of generating you should see a directory listening in your browser.
|
75
|
+
|
76
|
+
## Usage Terminal
|
77
|
+
Usage: ehg [options]
|
78
|
+
-s, --server [HOST_AND_PORT] start the rack server, default: 0.0.0.0:9292
|
79
|
+
-g, --generate [PROJECT] generate one or all projects, default: all
|
80
|
+
-i, --init initialize ehg workspace
|
81
|
+
-c, --create [PROJECT] create a new project from template, default: demo
|
82
|
+
-h, --help Show this message
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
# Resources
|
87
|
+
|
88
|
+
> "[Configuration](https://github.com/creative-workflow/easy-html-generator/blob/master/docs/CONFIGURATION.md)"
|
89
|
+
|
90
|
+
> "[Generators](https://github.com/creative-workflow/easy-html-generator/blob/master/docs/GENERATORS.md)"
|
91
|
+
|
92
|
+
>"[Contributing](https://github.com/creative-workflow/easy-html-generator/blob/master/docs/CONTRIBUTING.md)"
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'easy_html_generator/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'easy_html_generator'
|
9
|
+
spec.version = EasyHtmlGenerator::VERSION
|
10
|
+
spec.licenses = 'MIT'
|
11
|
+
spec.authors = ["Tom Hanoldt", "Alex Illmayer"]
|
12
|
+
|
13
|
+
spec.summary = "This gem is a powerful and easy to use web development tool that helps developing modern web sites by generating static html pagespec."
|
14
|
+
spec.description = "This gem is a powerful and easy to use web development tool that helps developing modern web sites by generating static html pagespec.
|
15
|
+
It uses CoffeScript, Sass, Haml, Bootstrap, HeadJs, Bower, Grunt, Google Anlaytics and minimizes coffee-, javascript-, sass-, css-, png- and image-filespec."
|
16
|
+
|
17
|
+
spec.email = ['monotom@gmail.com']
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
19
|
+
spec.homepage = 'https://github.com/creative-workflow/easy-html-generator'
|
20
|
+
|
21
|
+
spec.executables = ["ehg"]
|
22
|
+
|
23
|
+
spec.required_ruby_version = '>= 2.0.0'
|
24
|
+
|
25
|
+
spec.bindir = "bin"
|
26
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
27
|
+
|
28
|
+
spec.require_paths = ["lib", "src/shared/lib"]
|
29
|
+
|
30
|
+
spec.add_runtime_dependency 'rack'
|
31
|
+
spec.add_runtime_dependency 'thin'
|
32
|
+
spec.add_runtime_dependency 'rack-contrib'
|
33
|
+
spec.add_runtime_dependency 'shotgun'
|
34
|
+
spec.add_runtime_dependency 'haml'
|
35
|
+
spec.add_runtime_dependency 'sass'
|
36
|
+
spec.add_runtime_dependency 'coffee-script'
|
37
|
+
spec.add_runtime_dependency 'bootstrap-sass'
|
38
|
+
spec.add_runtime_dependency 'actionview'
|
39
|
+
spec.add_runtime_dependency 'cssminify'
|
40
|
+
spec.add_runtime_dependency 'uglifier'
|
41
|
+
spec.add_runtime_dependency 'htmlcompressor'
|
42
|
+
spec.add_runtime_dependency 'colorize'
|
43
|
+
spec.add_runtime_dependency 'piet'
|
44
|
+
spec.add_runtime_dependency 'piet-binary'
|
45
|
+
spec.add_runtime_dependency 'xml-sitemap'
|
46
|
+
|
47
|
+
spec.add_development_dependency 'rake'
|
48
|
+
spec.add_development_dependency 'rspec'
|
49
|
+
spec.add_development_dependency 'simplecov'
|
50
|
+
spec.add_development_dependency 'rack-test'
|
51
|
+
spec.add_development_dependency 'rubocop'
|
52
|
+
spec.add_development_dependency 'bundler'
|
53
|
+
#spec.add_development_dependency 'ruby-prof'
|
54
|
+
end
|
@@ -68,80 +68,3 @@ class EasyHtmlGenerator::Config
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
72
|
-
# class EasyHtmlGenerator::Config
|
73
|
-
# def self.from_file(path)
|
74
|
-
# return unless File.exist? path
|
75
|
-
#
|
76
|
-
# ConfigHash.new YAML.load(File.open(path))
|
77
|
-
# end
|
78
|
-
#
|
79
|
-
# # symbolizes the keys and makes the hash accessable via object attributes
|
80
|
-
# class ConfigHash < Hash
|
81
|
-
# def initialize(hash = nil)
|
82
|
-
# super
|
83
|
-
# return unless hash
|
84
|
-
#
|
85
|
-
# hash = self.class.symbolize_keys hash
|
86
|
-
# hash.each { |k, v| self[k] = v }
|
87
|
-
# end
|
88
|
-
#
|
89
|
-
# def method_missing(name, *args)
|
90
|
-
# # setter
|
91
|
-
# if /^(\w+)=$/ =~ name
|
92
|
-
# self[Regexp.last_match(1).to_sym] = args[0]
|
93
|
-
# # getter
|
94
|
-
# else
|
95
|
-
# return super.method_missing name unless key? name
|
96
|
-
# end
|
97
|
-
#
|
98
|
-
# self[name]
|
99
|
-
# end
|
100
|
-
#
|
101
|
-
# def self.symbolize_keys(obj)
|
102
|
-
# case obj
|
103
|
-
# when Array
|
104
|
-
# inject_array(obj)
|
105
|
-
# when Hash
|
106
|
-
# inject_hash(obj)
|
107
|
-
# else
|
108
|
-
# obj
|
109
|
-
# end
|
110
|
-
# end
|
111
|
-
#
|
112
|
-
# def self.inject_array(obj)
|
113
|
-
# obj.each_with_object([]) do |res, val|
|
114
|
-
# res << case val
|
115
|
-
# when Hash, Array
|
116
|
-
# symbolize_keys(val)
|
117
|
-
# else
|
118
|
-
# val
|
119
|
-
# end
|
120
|
-
# res
|
121
|
-
# end
|
122
|
-
# end
|
123
|
-
#
|
124
|
-
# def self.inject_hash(obj)
|
125
|
-
# obj.each_with_object(ConfigHash.new) do |res, (key, val)|
|
126
|
-
# nkey = inject_hash_key key
|
127
|
-
# nval = inject_hash_value val
|
128
|
-
# res[nkey] = nval
|
129
|
-
# res
|
130
|
-
# end
|
131
|
-
# end
|
132
|
-
#
|
133
|
-
# def self.inject_hash_key(key)
|
134
|
-
# case key
|
135
|
-
# when String then return key.to_sym
|
136
|
-
# else return key
|
137
|
-
# end
|
138
|
-
# end
|
139
|
-
#
|
140
|
-
# def self.inject_hash_value(val)
|
141
|
-
# case val
|
142
|
-
# when Hash, Array then symbolize_keys(val)
|
143
|
-
# else val
|
144
|
-
# end
|
145
|
-
# end
|
146
|
-
# end
|
147
|
-
# end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'colorize'
|
3
|
-
require 'fileutils'
|
4
|
-
require 'easy_html_generator/generators'
|
5
3
|
|
6
4
|
# this is the generator base class
|
7
5
|
class EasyHtmlGenerator::Generator::Base
|
@@ -12,68 +10,36 @@ class EasyHtmlGenerator::Generator::Base
|
|
12
10
|
@config = config
|
13
11
|
end
|
14
12
|
|
15
|
-
def
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
def dest_path
|
20
|
-
"#{@project.dist_path}/#{@config.dest}"
|
21
|
-
end
|
22
|
-
|
23
|
-
def log_running
|
24
|
-
log "#{self.class.name.yellow}"
|
13
|
+
def enabled?
|
14
|
+
!!@config[:enabled]
|
25
15
|
end
|
26
16
|
|
27
17
|
def generate
|
28
|
-
return unless
|
18
|
+
return unless enabled?
|
29
19
|
|
30
20
|
log_running
|
31
21
|
|
32
|
-
|
33
|
-
|
34
|
-
FileUtils.mkdir_p dest_path
|
35
|
-
|
36
|
-
walk_files(selector) do |i, o|
|
37
|
-
next unless should_do_file? i
|
38
|
-
|
39
|
-
do_file(i, o)
|
22
|
+
tasks.each do |task|
|
23
|
+
generate! @config.merge(task)
|
40
24
|
end
|
41
25
|
end
|
42
26
|
|
43
|
-
def
|
44
|
-
|
45
|
-
output_file = input_to_output_file(input_file)
|
46
|
-
|
47
|
-
yield(input_file, output_file)
|
48
|
-
end
|
27
|
+
def generate!(_config)
|
28
|
+
fail NotImplementedError.new "#{self.class.name} is an abstract class."
|
49
29
|
end
|
50
30
|
|
51
|
-
def
|
52
|
-
|
31
|
+
def repetitive?
|
32
|
+
@config.key? :repetitive
|
53
33
|
end
|
54
34
|
|
55
|
-
def
|
56
|
-
|
57
|
-
end
|
35
|
+
def tasks
|
36
|
+
return [@config] unless repetitive?
|
58
37
|
|
59
|
-
|
60
|
-
input
|
38
|
+
@config[:repetitive]
|
61
39
|
end
|
62
40
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
log "-> do_file #{src.sub(@project.src_path, '').green}"
|
67
|
-
|
68
|
-
FileUtils.mkdir_p File.dirname(target)
|
69
|
-
|
70
|
-
args.push target
|
71
|
-
i = File.read(src)
|
72
|
-
o = do_input(i, *args)
|
73
|
-
|
74
|
-
File.write(target, o)
|
75
|
-
|
76
|
-
EasyHtmlGenerator::Checksum.store_file(src)
|
41
|
+
def log_running
|
42
|
+
log "#{self.class.name.yellow}"
|
77
43
|
end
|
78
44
|
|
79
45
|
def log(msg)
|
@@ -81,15 +47,11 @@ class EasyHtmlGenerator::Generator::Base
|
|
81
47
|
.sub('EasyHtmlGenerator::', '')}"
|
82
48
|
end
|
83
49
|
|
84
|
-
def
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
default_prefix = @project.dist_path
|
91
|
-
path.sub!('dist://', '')
|
92
|
-
end
|
93
|
-
File.join(default_prefix, path)
|
50
|
+
def file_changed?(file)
|
51
|
+
EasyHtmlGenerator::Checksum.file_changed? file
|
52
|
+
end
|
53
|
+
|
54
|
+
def store_file_hash(file)
|
55
|
+
EasyHtmlGenerator::Checksum.store_file(file)
|
94
56
|
end
|
95
57
|
end
|
@@ -6,26 +6,16 @@ require 'easy_html_generator/generator/base'
|
|
6
6
|
class EasyHtmlGenerator::Generator::Combine <
|
7
7
|
EasyHtmlGenerator::Generator::Base
|
8
8
|
|
9
|
-
def generate
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
do_config config
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def do_config(config)
|
20
|
-
target_file = resolve_path_prefix(config.file, @project.dist_path)
|
21
|
-
o = ''
|
22
|
-
config.files.each do |file_pattern|
|
23
|
-
resolved_pattern = resolve_path_prefix(file_pattern, @project.dist_path)
|
24
|
-
Dir[resolved_pattern].each do |file|
|
25
|
-
next if target_file == file
|
26
|
-
o += File.read(file) + "\n"
|
9
|
+
def generate!(config)
|
10
|
+
result = ''
|
11
|
+
config.sources.each do |file_pattern|
|
12
|
+
Dir[file_pattern].each do |file|
|
13
|
+
next if config.target == file
|
14
|
+
result += File.read(file) + "\n"
|
27
15
|
end
|
28
16
|
end
|
29
|
-
File.
|
17
|
+
FileUtils.mkdir_p File.dirname(config.target)
|
18
|
+
|
19
|
+
File.write(config.target, result)
|
30
20
|
end
|
31
21
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'colorize'
|
3
|
+
|
4
|
+
# this is the generator base class
|
5
|
+
class EasyHtmlGenerator::Generator::Compile::Base <
|
6
|
+
EasyHtmlGenerator::Generator::Base
|
7
|
+
|
8
|
+
def generate!(config)
|
9
|
+
walk_files(config) do |input_file, output_file|
|
10
|
+
next unless file_changed? input_file
|
11
|
+
|
12
|
+
do_file(input_file, output_file, config)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def walk_files(config)
|
17
|
+
selector = File.join(config.source, config.selector)
|
18
|
+
|
19
|
+
Dir[selector].each do |input_file|
|
20
|
+
output_file = input_to_output_file(input_file, config)
|
21
|
+
|
22
|
+
yield(input_file, output_file)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def input_to_output_file(input_file, config)
|
27
|
+
input_file.sub(config.source, config.target)
|
28
|
+
end
|
29
|
+
|
30
|
+
def do_input!(_input, _input_file)
|
31
|
+
fail NotImplementedError.new "#{self.class.name} is an abstract class."
|
32
|
+
end
|
33
|
+
|
34
|
+
def do_file(input_file, output_file, config)
|
35
|
+
return unless File.exist?(input_file) && File.file?(input_file)
|
36
|
+
|
37
|
+
log "-> do_file #{input_file.sub(@project.src_path, '').green}"
|
38
|
+
|
39
|
+
FileUtils.mkdir_p File.dirname(output_file)
|
40
|
+
|
41
|
+
input_content = File.read(input_file)
|
42
|
+
|
43
|
+
output_content = do_input!(input_content, input_file, output_file, config)
|
44
|
+
|
45
|
+
store_file_hash(input_file)
|
46
|
+
|
47
|
+
return unless output_content
|
48
|
+
|
49
|
+
File.write(output_file, output_content)
|
50
|
+
end
|
51
|
+
end
|
@@ -1,30 +1,23 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'coffee_script'
|
3
|
-
require 'easy_html_generator/generator/base'
|
3
|
+
require 'easy_html_generator/generator/compile/base'
|
4
4
|
|
5
5
|
# this generator coffee sass files from src folder and copies them
|
6
6
|
# to the dist folder
|
7
7
|
class EasyHtmlGenerator::Generator::Compile::Coffee <
|
8
|
-
EasyHtmlGenerator::Generator::Base
|
8
|
+
EasyHtmlGenerator::Generator::Compile::Base
|
9
9
|
|
10
|
-
def
|
11
|
-
super(project, config)
|
12
|
-
|
13
|
-
@config.src = project.config.paths.src.scripts
|
14
|
-
@config.dest = project.config.paths.dist.scripts
|
15
|
-
end
|
16
|
-
|
17
|
-
def do_input(input, src = 'inline')
|
10
|
+
def do_input!(input, input_file = 'inline', *_args)
|
18
11
|
result = CoffeeScript.compile input
|
19
12
|
|
20
13
|
return result unless @config.minimize
|
21
14
|
|
22
15
|
EasyHtmlGenerator::Generator::Minimize::Js.compress result
|
23
16
|
rescue StandardError => e
|
24
|
-
raise e, "#{e.message} in #{
|
17
|
+
raise e, "#{e.message} in #{input_file} ", e.backtrace
|
25
18
|
end
|
26
19
|
|
27
|
-
def input_to_output_file(
|
28
|
-
super(
|
20
|
+
def input_to_output_file(input_file, config)
|
21
|
+
super(input_file, config).gsub('.js.coffee', '.js')
|
29
22
|
end
|
30
23
|
end
|