easy_html_generator 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +6 -0
  3. data/.gitignore +12 -0
  4. data/.rubocop.yml +18 -0
  5. data/.travis.yml +14 -0
  6. data/Gemfile +3 -0
  7. data/README.md +51 -337
  8. data/Rakefile +42 -0
  9. data/config.ru +4 -0
  10. data/docs/CONFIGURATION.md +84 -0
  11. data/{CONTRIBUTING.md → docs/CONTRIBUTING.md} +2 -0
  12. data/docs/GENERATORS.md +210 -0
  13. data/docs/GETSTARTED.md +92 -0
  14. data/easy_html_generator.gemspec +54 -0
  15. data/lib/easy_html_generator/checksum.rb +4 -0
  16. data/lib/easy_html_generator/config.rb +0 -77
  17. data/lib/easy_html_generator/generator/base.rb +20 -58
  18. data/lib/easy_html_generator/generator/combine.rb +9 -19
  19. data/lib/easy_html_generator/generator/compile/base.rb +51 -0
  20. data/lib/easy_html_generator/generator/compile/coffee.rb +6 -13
  21. data/lib/easy_html_generator/generator/compile/haml/helper/activesupport_override.rb +1 -6
  22. data/lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb +7 -7
  23. data/lib/easy_html_generator/generator/compile/haml.rb +20 -45
  24. data/lib/easy_html_generator/generator/compile/sass.rb +9 -13
  25. data/lib/easy_html_generator/generator/copy.rb +7 -14
  26. data/lib/easy_html_generator/generator/delete.rb +4 -13
  27. data/lib/easy_html_generator/generator/minimize/css.rb +5 -12
  28. data/lib/easy_html_generator/generator/minimize/html.rb +5 -12
  29. data/lib/easy_html_generator/generator/minimize/images.rb +6 -20
  30. data/lib/easy_html_generator/generator/minimize/js.rb +5 -12
  31. data/lib/easy_html_generator/generator/service/analytics.rb +19 -19
  32. data/lib/easy_html_generator/generator/service/bower.rb +21 -17
  33. data/lib/easy_html_generator/generator/service/grunt.rb +12 -11
  34. data/lib/easy_html_generator/generator/service/sitemap.rb +33 -0
  35. data/lib/easy_html_generator/generator/structure.rb +2 -6
  36. data/lib/easy_html_generator/generator.rb +6 -6
  37. data/lib/easy_html_generator/project.rb +5 -0
  38. data/lib/easy_html_generator/project_path_resolver.rb +57 -0
  39. data/lib/easy_html_generator/rack_dispatcher.rb +1 -1
  40. data/lib/easy_html_generator/version.rb +4 -0
  41. data/lib/easy_html_generator/workspace.rb +1 -1
  42. data/lib/easy_html_generator.rb +19 -18
  43. data/src/demo/assets/styles/app.css.sass +47 -2
  44. data/src/demo/lib/helper/projecthelper.rb +3 -0
  45. data/src/demo/project.yml +142 -0
  46. data/src/demo/views/index/_bower_and_grunt.haml +7 -0
  47. data/src/demo/views/index/_dry.haml +16 -0
  48. data/src/demo/views/index/_haml_sass_coffee.haml +11 -0
  49. data/src/demo/views/index/_inline_coffee_and_sass.haml +43 -0
  50. data/src/demo/views/index/_sass_mixins.haml +76 -0
  51. data/src/demo/views/index.html.haml +13 -1
  52. data/src/demo/views/layout/_assets.javascripts.haml +7 -0
  53. data/src/demo/views/layout/_assets.metadata.haml +12 -0
  54. data/src/demo/views/layout/_assets.stylesheets.haml +9 -0
  55. data/src/demo/views/layout/_footer.haml +3 -0
  56. data/src/demo/views/layout/_header.haml +1 -0
  57. data/src/demo/views/layout.haml +8 -4
  58. data/src/demo/views/plain.html +1 -0
  59. data/src/shared/assets/styles/mixins/_bootstrap-fixes.sass +12 -0
  60. data/src/shared/assets/styles/mixins/_headjs-bootstrap-mediaqueries.sass +30 -0
  61. data/src/shared/project.yml +56 -35
  62. data/src/template/project.yml +57 -43
  63. metadata +75 -7
  64. data/src/demo/views/index/_lore_ipsum.haml +0 -1
@@ -2,11 +2,6 @@
2
2
 
3
3
  # this module overrides some active support methods for working paths etc.
4
4
  module ActivesupportOverride
5
- def stylesheet_link_tag(path, media = 'screen')
6
- '<link href="' + path_to_css(path) + '" media="' + media +
7
- '" rel="stylesheet" type="text/css" />'
8
- end
9
-
10
5
  def javascript_include_tag(path)
11
6
  '<script src="' + path_to_js(path) + '"></script>'
12
7
  end
@@ -24,7 +19,7 @@ module ActivesupportOverride
24
19
  '<link rel="' + relation + '" href="' + source + '"' + type + '/>'
25
20
  end
26
21
 
27
- def path_to_css(path)
22
+ def path_to_stylesheet(path, _options = {})
28
23
  return path if external_path?(path)
29
24
  @project.uri_path_to(:styles, path)
30
25
  end
@@ -17,14 +17,14 @@ module AssetHelper
17
17
  def with_coffee(&block)
18
18
  input = capture_haml(&block)
19
19
  content_tag :script do
20
- raw @project.generators.compile_coffee.do_input input
20
+ raw @project.generators.compile_coffee.do_input! input
21
21
  end
22
22
  end
23
23
 
24
24
  def with_sass(&block)
25
25
  input = capture_haml(&block)
26
26
  content_tag :style do
27
- raw @project.generators.compile_sass.do_input input
27
+ raw @project.generators.compile_sass.do_input! input
28
28
  end
29
29
  end
30
30
 
@@ -43,21 +43,21 @@ module AssetHelper
43
43
  end
44
44
 
45
45
  def headjs_stylesheet_link_tag(tag, path)
46
- headjs_javascript_include_tag(tag, path_to_css(path))
46
+ headjs_javascript_include_tag(tag, path_to_stylesheet(path))
47
47
  end
48
48
 
49
49
  def inline_stylesheet_link_tag(path)
50
50
  return path if external_path?(path)
51
51
 
52
52
  styles_path = @project.dist_path_to(:styles, path)
53
- if File.exists? styles_path
53
+ if File.exist? styles_path
54
54
  path = styles_path
55
55
  else
56
56
  path = File.join(@project.dist_path, path)
57
57
  end
58
58
 
59
59
  content_tag :style do
60
- raw @project.generators.minimize_css.do_input File.read(path)
60
+ raw @project.generators.minimize_css.do_input! File.read(path)
61
61
  end
62
62
  end
63
63
 
@@ -65,14 +65,14 @@ module AssetHelper
65
65
  return path if external_path?(path)
66
66
 
67
67
  scripts_path = @project.dist_path_to(:scripts, path)
68
- if File.exists? scripts_path
68
+ if File.exist? scripts_path
69
69
  path = scripts_path
70
70
  else
71
71
  path = File.join(@project.dist_path, path)
72
72
  end
73
73
 
74
74
  content_tag :script do
75
- raw @project.generators.minimize_js.do_input File.read(path)
75
+ raw @project.generators.minimize_js.do_input! File.read(path)
76
76
  end
77
77
  end
78
78
  end
@@ -1,28 +1,31 @@
1
1
  # encoding: utf-8
2
- require 'fileutils'
3
2
  require 'haml'
4
- require 'easy_html_generator/generator/base'
3
+ require 'easy_html_generator/generator/compile/base'
5
4
 
6
5
  # this generator compiles haml files from src folder and copies them
7
6
  # to the dist folder
8
7
  class EasyHtmlGenerator::Generator::Compile::Haml <
9
- EasyHtmlGenerator::Generator::Base
8
+ EasyHtmlGenerator::Generator::Compile::Base
10
9
 
11
10
  require 'easy_html_generator/generator/compile/haml/context'
12
11
  require 'easy_html_generator/generator/compile/haml/layout'
13
12
 
14
- def initialize(project, config)
15
- super(project, config)
16
- @config.src = project.config.paths.src.views
17
- @config.dest = project.config.paths.dist.views
13
+ def do_input!(input, input_file, *_args)
14
+ file_name = File.basename input_file
15
+ scope = file_name.split('.').first
16
+ context = Context.new(@project, @config, scope)
17
+ layout = Layout.layout_from_file(@project.src_path_to(:views),
18
+ input_file, @config.renderer)
19
+
20
+ do_input(input, layout, context, scope)
21
+
22
+ rescue StandardError => e
23
+ raise e, "#{e.message} in #{input_file} ", e.backtrace
18
24
  end
19
25
 
20
- def do_input(input, layout, context, scope, _input_file)
21
- # If the file being processed by Haml contains a yield statement,
22
- # the block passed to "render" will be called when it's hit.
26
+ def do_input(input, layout, context, scope)
23
27
  result = layout.render(context, body_class: scope) do
24
- # Render the actual page contents in place of the call to "yield".
25
- body = Haml::Engine.new(input, @config.renderer)
28
+ body = Haml::Engine.new(input, @config.renderer)
26
29
  body.render(context)
27
30
  end
28
31
 
@@ -31,40 +34,12 @@ class EasyHtmlGenerator::Generator::Compile::Haml <
31
34
  EasyHtmlGenerator::Generator::Minimize::Html.compress result
32
35
  end
33
36
 
34
- def should_do_file?(i)
35
- # dont check if file changed, because partials could have changed
36
- !File.basename(i).start_with? '_'
37
+ def file_changed?(file)
38
+ # regenerate all haml files except imported once
39
+ !File.basename(file).start_with? '_'
37
40
  end
38
41
 
39
- def input_to_output_file(i)
40
- super(i).gsub('.html.haml', '.html')
41
- end
42
-
43
- def generate
44
- return unless @config.enabled
45
-
46
- log_running
47
-
48
- FileUtils.mkdir_p dest_path
49
-
50
- walk_files(File.join(src_path, @config.selector)) do |i, o|
51
- next unless should_do_file? i
52
-
53
- compile_file i, o
54
- end
55
- end
56
-
57
- def compile_file(src, target)
58
- file_name = File.basename src
59
- scope = file_name.split('.').first
60
- context = Context.new(@project, @config, scope)
61
- layout = Layout.layout_from_file(@project.src_path_to(:views),
62
- src, @config.renderer)
63
-
64
- begin
65
- do_file(src, target, layout, context, scope)
66
- rescue StandardError => e
67
- raise e, "#{e.message} in #{src} ", e.backtrace
68
- end
42
+ def input_to_output_file(input_file, config)
43
+ super(input_file, config).gsub('.html.haml', '.html')
69
44
  end
70
45
  end
@@ -2,12 +2,12 @@
2
2
  require 'sass'
3
3
 
4
4
  require 'easy_html_generator'
5
- require 'easy_html_generator/generator/base'
5
+ require 'easy_html_generator/generator/compile/base'
6
6
 
7
7
  # this generator compiles sass files from src folder and copies them
8
8
  # to the dist folder
9
9
  class EasyHtmlGenerator::Generator::Compile::Sass <
10
- EasyHtmlGenerator::Generator::Base
10
+ EasyHtmlGenerator::Generator::Compile::Base
11
11
 
12
12
  def self.add_load_path(path)
13
13
  ::Sass.load_paths << path unless ::Sass.load_paths.include?(path)
@@ -19,12 +19,9 @@ class EasyHtmlGenerator::Generator::Compile::Sass <
19
19
  super(project, config)
20
20
 
21
21
  self.class.add_load_path "#{@project.src_path_to :styles}"
22
-
23
- @config.src = project.config.paths.src.styles
24
- @config.dest = project.config.paths.dist.styles
25
22
  end
26
23
 
27
- def do_input(input, src='inline')
24
+ def do_input!(input, input_file = 'inline', *_args)
28
25
  renderer = ::Sass::Engine.new(input)
29
26
  result = renderer.render
30
27
 
@@ -32,16 +29,15 @@ class EasyHtmlGenerator::Generator::Compile::Sass <
32
29
 
33
30
  EasyHtmlGenerator::Generator::Minimize::Css.compress result
34
31
  rescue StandardError => e
35
- raise e, "#{e.message} in #{src} ", e.backtrace
32
+ raise e, "#{e.message} in #{input_file} ", e.backtrace
36
33
  end
37
34
 
38
-
39
- def should_do_file?(i)
40
- # dont check if file changed, because partials could have changed
41
- !File.basename(i).start_with? '_'
35
+ def file_changed?(file)
36
+ # regenerate all sass files except imported once
37
+ !File.basename(file).start_with? '_'
42
38
  end
43
39
 
44
- def input_to_output_file(i)
45
- super(i).gsub('.css.sass', '.css')
40
+ def input_to_output_file(input_file, config)
41
+ super(input_file, config).gsub('.css.sass', '.css')
46
42
  end
47
43
  end
@@ -3,33 +3,26 @@ require 'fileutils'
3
3
  require 'easy_html_generator/generator/base'
4
4
 
5
5
  # this generator copies files from src ro dist folder
6
- class EasyHtmlGenerator::Generator::Copy < EasyHtmlGenerator::Generator::Base
7
- def generate
8
- return unless @config.enabled
6
+ class EasyHtmlGenerator::Generator::Copy <
7
+ EasyHtmlGenerator::Generator::Base
9
8
 
10
- log_running
9
+ def generate!(config)
10
+ selector = config.key?(:selector) ? config[:selector] : '**/*'
11
11
 
12
- @config.dirs.each do |config|
13
- src_path = resolve_path_prefix(config.source, @project.src_path)
14
- dest_path = resolve_path_prefix(config.target, @project.dist_path)
15
-
16
- self.class.copy_r(src_path, dest_path, config.selector)
17
- end
12
+ self.class.copy_r(config.source, config.target, selector)
18
13
  end
19
14
 
20
15
  # cannot use copy_entry or cp_r with symbolic existent links in target
21
- # FileUtils::copy_entry(src_dir, output_folder, true, false, true)
22
- # if File.directory? src_dir
23
16
  def self.copy_r(src_path, dest_path, selector)
24
17
  return unless File.exist? src_path
25
18
 
26
- FileUtils.mkdir_p dest_path
27
-
28
19
  Dir[File.join(src_path, selector)].each do |input_file|
29
20
  next if input_file.empty?
30
21
 
31
22
  output_file = input_file.sub(src_path, dest_path)
32
23
 
24
+ FileUtils.mkdir_p File.dirname(output_file)
25
+
33
26
  copy(input_file, output_file)
34
27
  end
35
28
  end
@@ -3,19 +3,10 @@ require 'fileutils'
3
3
  require 'easy_html_generator/generator/base'
4
4
 
5
5
  # this generator deletes in the dest folder
6
- class EasyHtmlGenerator::Generator::Delete < EasyHtmlGenerator::Generator::Base
7
- def generate
8
- return unless @config.enabled
6
+ class EasyHtmlGenerator::Generator::Delete <
7
+ EasyHtmlGenerator::Generator::Base
9
8
 
10
- log_running
11
-
12
- @config.files.each do |file_pattern|
13
- resolved_pattern = resolve_path_prefix(file_pattern, @project.dist_path)
14
- Dir[resolved_pattern].each do |file|
15
- EasyHtmlGenerator::Checksum.invalidate_file file
16
-
17
- FileUtils.rm_rf file
18
- end
19
- end
9
+ def generate!(config)
10
+ FileUtils.rm_rf Dir[config.source]
20
11
  end
21
12
  end
@@ -1,25 +1,18 @@
1
1
  # encoding: utf-8
2
2
  require 'cssminify'
3
- require 'easy_html_generator/generator/base'
3
+ require 'easy_html_generator/generator/compile/base'
4
4
 
5
5
  # this generator minifies css files from src folder and copies them
6
6
  # to the dist folder
7
7
  class EasyHtmlGenerator::Generator::Minimize::Css <
8
- EasyHtmlGenerator::Generator::Base
8
+ EasyHtmlGenerator::Generator::Compile::Base
9
9
 
10
- def initialize(project, config)
11
- super(project, config)
12
-
13
- @config.src = project.config.paths.src.styles
14
- @config.dest = project.config.paths.dist.styles
15
- end
16
-
17
- def do_input(input, *_args)
10
+ def do_input!(input, *_args)
18
11
  self.class.compress input
19
12
  end
20
13
 
21
- def input_to_output_file(i)
22
- super(i).gsub('.css', "#{@config.prefix_extension}.css")
14
+ def input_to_output_file(input_file, config)
15
+ super(input_file, config).gsub('.css', "#{config.prefix_extension}.css")
23
16
  end
24
17
 
25
18
  def self.compress(input)
@@ -1,25 +1,18 @@
1
1
  # encoding: utf-8
2
2
  require 'htmlcompressor'
3
- require 'easy_html_generator/generator/base'
3
+ require 'easy_html_generator/generator/compile/base'
4
4
 
5
5
  # this generator minifies html files from src folder and copies them
6
6
  # to the dist folder
7
7
  class EasyHtmlGenerator::Generator::Minimize::Html <
8
- EasyHtmlGenerator::Generator::Base
8
+ EasyHtmlGenerator::Generator::Compile::Base
9
9
 
10
- def initialize(project, config)
11
- super(project, config)
12
-
13
- @config.src = project.config.paths.src.views
14
- @config.dest = project.config.paths.dist.views
15
- end
16
-
17
- def do_input(input, *_args)
10
+ def do_input!(input, *_args)
18
11
  self.class.compress input
19
12
  end
20
13
 
21
- def input_to_output_file(i)
22
- super(i).gsub('.html', "#{@config.prefix_extension}.html")
14
+ def input_to_output_file(input_file, config)
15
+ super(input_file, config).gsub('.html', "#{config.prefix_extension}.html")
23
16
  end
24
17
 
25
18
  def self.compressor
@@ -1,32 +1,18 @@
1
1
  # encoding: utf-8
2
2
  require 'piet'
3
- require 'easy_html_generator/generator/base'
3
+ require 'easy_html_generator/generator/compile/base'
4
4
 
5
5
  # this generator minifies image files from src folder and copies them
6
6
  # to the dist folder
7
7
  class EasyHtmlGenerator::Generator::Minimize::Images <
8
- EasyHtmlGenerator::Generator::Base
8
+ EasyHtmlGenerator::Generator::Compile::Base
9
9
 
10
- def initialize(project, config)
11
- super(project, config)
10
+ def do_input!(_input, input_file, output_file, config)
11
+ FileUtils.copy(input_file, output_file) unless input_file == output_file
12
12
 
13
- @config.src = project.config.paths.src.images
14
- @config.dest = project.config.paths.dist.images
15
- end
16
-
17
- def do_file(src, target, *args)
18
- return unless File.exist?(src) && File.file?(src)
19
- log "-> do_file #{src}"
20
-
21
- FileUtils.mkdir_p File.dirname(target)
22
-
23
- args.push target
24
-
25
- FileUtils.copy(src, target)
26
-
27
- Piet.optimize(target, @config.options)
13
+ Piet.optimize(output_file, config.options)
28
14
 
29
- EasyHtmlGenerator::Checksum.store_file(src)
15
+ nil
30
16
  rescue StandardError
31
17
  log '-> you have to install "optipng" and "jpegoptim"'.red
32
18
  end
@@ -1,25 +1,18 @@
1
1
  # encoding: utf-8
2
2
  require 'uglifier'
3
- require 'easy_html_generator/generator/base'
3
+ require 'easy_html_generator/generator/compile/base'
4
4
 
5
5
  # this generator minifies js files from src folder and copies them
6
6
  # to the dist folder
7
7
  class EasyHtmlGenerator::Generator::Minimize::Js <
8
- EasyHtmlGenerator::Generator::Base
8
+ EasyHtmlGenerator::Generator::Compile::Base
9
9
 
10
- def initialize(project, config)
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, *_args)
10
+ def do_input!(input, *_args)
18
11
  self.class.compress input
19
12
  end
20
13
 
21
- def input_to_output_file(i)
22
- super(i).gsub('.js', "#{@config.prefix_extension}.js")
14
+ def input_to_output_file(input_file, config)
15
+ super(input_file, config).gsub('.js', "#{config.prefix_extension}.js")
23
16
  end
24
17
 
25
18
  def self.compress(input)
@@ -1,34 +1,34 @@
1
1
  # encoding: utf-8
2
- require 'easy_html_generator/generator/base'
2
+
3
+ require 'easy_html_generator/generator/compile/base'
3
4
 
4
5
  # this generator adds web tracking snippets to files in the dist folder
5
6
  class EasyHtmlGenerator::Generator::Service::Analytics <
6
- EasyHtmlGenerator::Generator::Base
7
+ EasyHtmlGenerator::Generator::Compile::Base
7
8
 
8
- def generate
9
- return unless @config.enabled
9
+ def do_input!(input, _input_file, _output_file, config)
10
+ return if input.include? begin_marker(config)
10
11
 
11
- log_running
12
+ analytics_code = build_content(config)
12
13
 
13
- selector = File.join(@project.dist_path_to(:views),
14
- @config.append_to_files)
15
- Dir[selector].each do |file|
16
- do_google file
17
- end
14
+ input.sub('</head>', "#{analytics_code}</head>")
18
15
  end
19
16
 
20
- def do_google(file)
21
- return unless @config.google.enabled
22
-
23
- content = File.read(file)
24
- return if file.include? '<!-- Google Analytics -->'
17
+ def begin_marker(config)
18
+ "<!-- #{config.name} Analytics -->"
19
+ end
25
20
 
26
- code = @config.google.code.sub('{GOOGLE_UA_ID}', @config.google.id)
21
+ def end_marker(config)
22
+ "<!-- End #{config.name} Analytics -->"
23
+ end
27
24
 
28
- code = "<!-- Google Analytics -->#{code}<!-- End Google Analytics -->"
25
+ def build_content(config)
26
+ content = config.code
29
27
 
30
- content = content.sub('</head>', "#{code}</head>")
28
+ config.params.each do |key, value|
29
+ content.sub!("{#{key}}", value)
30
+ end
31
31
 
32
- File.write(file, content)
32
+ "#{begin_marker(config)} #{content} #{end_marker(config)}"
33
33
  end
34
34
  end
@@ -6,29 +6,33 @@ require 'easy_html_generator/generator/base'
6
6
  class EasyHtmlGenerator::Generator::Service::Bower <
7
7
  EasyHtmlGenerator::Generator::Base
8
8
 
9
- def initialize(project, config)
10
- super(project, config)
9
+ def generate!(_config)
10
+ return unless File.exist? bower_file
11
+ return unless file_changed? bower_file
11
12
 
12
- @config.src = ''
13
- @config.dest = ''
14
- end
13
+ log ` #{bower_command} `
15
14
 
16
- def do_file(bower_file, *_args)
17
- input_folder = File.dirname(bower_file)
18
- output_folder = File.join(@project.dist_path, @config.target)
15
+ FileUtils.mkdir_p @config.target
19
16
 
20
- cmd = "cd #{input_folder} && bower install"
21
- cmd = "if which bower >/dev/null; then echo '\e[32mrunning bower\e[0m' \
22
- && #{cmd}; else echo '\e[31mplease install bower \
23
- \"npm install -g bower\" http://bower.io/ \e[0m'; fi"
17
+ EasyHtmlGenerator::Generator::Copy.copy_r(
18
+ bower_storage, @config.target, '**/*')
24
19
 
25
- log ` #{cmd} `
20
+ store_file_hash(bower_file)
21
+ end
26
22
 
27
- FileUtils.mkdir_p output_folder
23
+ def bower_storage
24
+ File.join(@config.source, 'bower_components')
25
+ end
28
26
 
29
- EasyHtmlGenerator::Generator::Copy.copy_r(
30
- "#{input_folder}/bower_components", output_folder, '**/*')
27
+ def bower_file
28
+ File.join(@config.source, 'bower.json')
29
+ end
30
+
31
+ def bower_command
32
+ command = "cd #{@config.source} && bower install --force-latest"
31
33
 
32
- EasyHtmlGenerator::Checksum.store_file(bower_file)
34
+ "if which bower >/dev/null; then echo '\e[32mrunning bower\e[0m' \
35
+ && #{command}; else echo '\e[31mplease install bower \
36
+ \"npm install -g bower\" http://bower.io/ \e[0m'; fi"
33
37
  end
34
38
  end
@@ -5,20 +5,21 @@ require 'easy_html_generator/generator/base'
5
5
  class EasyHtmlGenerator::Generator::Service::Grunt <
6
6
  EasyHtmlGenerator::Generator::Base
7
7
 
8
- def initialize(project, config)
9
- super(project, config)
8
+ def generate!(config)
9
+ return unless File.exist? config.source
10
+ log ` #{grunt_command(config)} `
11
+ end
10
12
 
11
- @config.src = ''
12
- @config.dest = ''
13
+ def grunt_folder(config)
14
+ File.dirname(config.source)
13
15
  end
14
16
 
15
- def do_file(grunt_file, *_args)
16
- input_folder = File.dirname(grunt_file)
17
+ def grunt_command(config)
18
+ command = "cd #{grunt_folder(config)} \
19
+ && npm install && grunt #{config.task}"
17
20
 
18
- cmd = "cd #{input_folder} && npm install && grunt #{@config.task}"
19
- cmd = "if which grunt >/dev/null; then echo '\e[32m | ->running grunt \
20
- \e[0m' && #{cmd}; else echo '\e[31mplease install grunt \
21
- \"npm install -g grunt\" http://gruntjs.com/ \e[0m'; fi"
22
- log ` #{cmd} `
21
+ "if which grunt >/dev/null; then echo '\e[32m | ->running grunt \
22
+ \e[0m' && #{command}; else echo '\e[31mplease install grunt \
23
+ \"npm install -g grunt\" http://gruntjs.com/ \e[0m'; fi"
23
24
  end
24
25
  end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+ require 'fileutils'
3
+ require 'xml-sitemap'
4
+ require 'easy_html_generator/generator/base'
5
+
6
+ # this generator combines files in the dist folder
7
+ class EasyHtmlGenerator::Generator::Service::Sitemap <
8
+ EasyHtmlGenerator::Generator::Base
9
+
10
+ def generate!(config)
11
+ files = Dir[config.selector]
12
+
13
+ files.map! do |file|
14
+ file.sub(@project.dist_path, '').sub(@project.name, '')
15
+ end
16
+ generate_sitemap(files, config)
17
+ end
18
+
19
+ def generate_sitemap(files, config)
20
+ map = XmlSitemap::Map.new(config.domain) do |m|
21
+ files.each do |file|
22
+ next if blacklisted?(file, config)
23
+ m.add file, updated: Date.today, period: :daily
24
+ end
25
+ end
26
+ map.render_to(config.target)
27
+ end
28
+
29
+ def blacklisted?(file, config)
30
+ return false if config.blacklist.nil?
31
+ config.blacklist.any? { |entry| file.include?(entry) }
32
+ end
33
+ end
@@ -1,5 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'find'
3
2
  require 'fileutils'
4
3
  require 'easy_html_generator/generator/base'
5
4
 
@@ -7,13 +6,10 @@ require 'easy_html_generator/generator/base'
7
6
  class EasyHtmlGenerator::Generator::Structure <
8
7
  EasyHtmlGenerator::Generator::Base
9
8
 
10
- def generate
11
- return unless @config.enabled
12
-
13
- log_running
14
-
9
+ def generate!(_config)
15
10
  @project.config.paths.dist.each do |_index, dir|
16
11
  next if dir.empty?
12
+
17
13
  FileUtils.mkdir_p("#{@project.dist_path}/#{dir}")
18
14
  end
19
15
  end
@@ -5,12 +5,6 @@ module EasyHtmlGenerator::Generator
5
5
  Dir[File.dirname(__FILE__) + '/generator/*.rb']
6
6
  .each { |file| require file }
7
7
 
8
- # this is a wrapper module for generator services
9
- module Service
10
- Dir[File.dirname(__FILE__) + '/generator/service/*.rb']
11
- .each { |file| require file }
12
- end
13
-
14
8
  # this is a wrapper module for compiling generators
15
9
  module Compile
16
10
  Dir[File.dirname(__FILE__) + '/generator/compile/*.rb']
@@ -22,4 +16,10 @@ module EasyHtmlGenerator::Generator
22
16
  Dir[File.dirname(__FILE__) + '/generator/minimize/*.rb']
23
17
  .each { |file| require file }
24
18
  end
19
+
20
+ # this is a wrapper module for generator services
21
+ module Service
22
+ Dir[File.dirname(__FILE__) + '/generator/service/*.rb']
23
+ .each { |file| require file }
24
+ end
25
25
  end
@@ -62,6 +62,9 @@ class EasyHtmlGenerator::Project
62
62
  def load_config(file)
63
63
  @config = EasyHtmlGenerator::Config.from_file file
64
64
  @config[:generate_on_request_path_match].map! { |p| Regexp.new(p) }
65
+ @config =
66
+ EasyHtmlGenerator::ProjectPathResolver.new(self).resolve_config @config
67
+
65
68
  EasyHtmlGenerator::Checksum.store_file file
66
69
  end
67
70
 
@@ -73,6 +76,8 @@ class EasyHtmlGenerator::Project
73
76
  return unless EasyHtmlGenerator::Checksum.file_changed? @config_file
74
77
  STDERR.puts " | -> reloading config(#{@config_file.green})"
75
78
 
79
+ EasyHtmlGenerator::Checksum.invalidate_all
80
+
76
81
  load_config @config_file
77
82
  load_generators
78
83
  end