|
1 |
| -namespace :css do |
2 |
| - source = "./dynamic/css" |
3 |
| - dest = "./dynamic/compiled" |
4 |
| - |
5 |
| - ########## |
6 |
| - # CSS Compressed build |
7 |
| - ########## |
8 |
| - desc "Compile all required CSS" |
9 |
| - task :build do |
10 |
| - # This code was largely inspired by this SO question |
11 |
| - # http://stackoverflow.com/questions/25399962/compass-from-ruby-sasscompiler-not-found |
12 |
| - # with addtional code and configuraion options drawn from: |
13 |
| - # https://github.com/Compass/compass/blob/350bcaa544f594bca972aaa29a9bdfddceee5d4f/cli/lib/compass/exec/global_options_parser.rb |
14 |
| - # https://github.com/Compass/compass/blob/350bcaa544f594bca972aaa29a9bdfddceee5d4f/cli/lib/compass/exec/project_options_parser.rb |
15 |
| - # NOTE(Drew): I made the choice here to start from the above SO question |
16 |
| - # and code snippets to make this call using the undocumented |
17 |
| - # Ruby API of Compass rather than building a shell call out |
18 |
| - # of a Ruby string and passing that to the OS layer. I don't |
19 |
| - # know if it's the right choice, but it's the choice I made. |
20 |
| - # Hopefully no one gets bit by it. |
21 |
| - require 'compass' |
22 |
| - require 'compass/sass_compiler' |
23 |
| - |
24 |
| - Compass.configuration.add_import_path "#{source}/imports" |
25 |
| - Compass.add_configuration({ |
26 |
| - :project_path => ".", |
27 |
| - :http_path => "/", |
28 |
| - :output_style => :compressed, |
29 |
| - :line_comments => false, |
30 |
| - :sass_path => source, |
31 |
| - :css_path => dest, |
32 |
| - :cache_path => "#{source}/.sass-cache", |
33 |
| - }, "basho_docs_configs") |
34 |
| - compiler = Compass.sass_compiler({ |
35 |
| - :only_sass_files => Dir.glob("#{source}/*.scss") |
36 |
| - }) |
37 |
| - compiler.compile! |
38 |
| - end |
| 1 | +# Rules: |
| 2 | +# build |
| 3 | +# build:css |
| 4 | +# build:js |
| 5 | +# build:debug |
| 6 | +# build:debug:css |
| 7 | +# build:debug:js |
| 8 | +# clean |
| 9 | +# clean:css |
| 10 | +# clean:js |
| 11 | +# watch |
| 12 | +# watch:css |
| 13 | +# watch:js |
| 14 | +# watch:debug |
| 15 | +# watch:debug:css |
| 16 | +# watch:debug:js |
39 | 17 |
|
40 |
| - ########## |
41 |
| - # CSS Debug build |
42 |
| - ########## |
43 |
| - desc "Compile all scss with the Nested style, and load all css into /static/css" |
44 |
| - task :debug do |
45 |
| - require 'compass' |
46 |
| - require 'compass/sass_compiler' |
47 |
| - |
48 |
| - #TODO(Drew): This is largely a duplicate of the above rule. Split it out |
49 |
| - # into it's own function. |
50 |
| - Compass.configuration.add_import_path "#{source}/imports" |
51 |
| - Compass.add_configuration({ |
52 |
| - :project_path => ".", |
53 |
| - :http_path => "/", |
54 |
| - :output_style => :nested, |
55 |
| - :line_comments => true, |
56 |
| - :sass_path => source, |
57 |
| - :css_path => dest, |
58 |
| - :cache_path => "#{source}/.sass-cache", |
59 |
| - }, "basho_docs_configs") |
60 |
| - compiler = Compass.sass_compiler({ |
61 |
| - :only_sass_files => Dir.glob("#{source}/*.scss") |
62 |
| - }) |
63 |
| - compiler.compile! |
64 |
| - end |
65 | 18 |
|
66 |
| - ########## |
67 |
| - # CSS Clean |
68 |
| - ########## |
69 |
| - desc "Delete generated CSS files" |
70 |
| - task :clean do |
71 |
| - #TODO(Drew): This is maybe a bit much to clear generated files. Consider |
72 |
| - # working out how to get the below dead code to work? |
73 |
| - FileUtils.rm_rf(dest) |
74 |
| - # Dir.foreach(dest) { |f| |
75 |
| - # if "#{f}" != '.' && "#{f}" != '..' |
76 |
| - # File.delete(File.join(dest, f)) |
77 |
| - # puts "Cleaning #{File.join(dest, f)}" |
78 |
| - # end |
79 |
| - # } |
| 19 | +$css_source = "./dynamic/css" |
| 20 | +$css_dest = "./dynamic/compiled" |
| 21 | + |
| 22 | + |
| 23 | +task :clean => ['clean:js', 'clean:css'] |
| 24 | +namespace :clean do |
| 25 | + |
| 26 | + task :js do |
| 27 | + puts "clean:js not yet implemented." |
| 28 | + end |
| 29 | + |
| 30 | + #TODO(Drew): This is maybe a bit much? Can we be more specific? |
| 31 | + task :css do |
| 32 | + FileUtils.rm_rf($css_dest) |
| 33 | + end |
| 34 | +end |
| 35 | + |
| 36 | + |
| 37 | +task :build => ['build:js', 'build:css'] |
| 38 | +namespace :build do |
| 39 | + |
| 40 | + task :js do |
| 41 | + puts "build:js not yet implemented." |
| 42 | + end |
| 43 | + |
| 44 | + task :css do |
| 45 | + compass_compile({ |
| 46 | + :output_style => :compressed, |
| 47 | + :line_comments => false |
| 48 | + }) |
| 49 | + end |
| 50 | + |
| 51 | + task :debug => ['clean', 'build:debug:js', 'build:debug:css'] |
| 52 | + namespace :debug do |
| 53 | + |
| 54 | + task :js do |
| 55 | + puts "build:debug:js not yet implemented." |
80 | 56 | end
|
81 | 57 |
|
82 |
| - ########## |
83 |
| - # CSS Watch |
84 |
| - ########## |
85 |
| - desc "Spin up a Watchr process to monitor changes in the CSS files" |
86 |
| - task :watch do |
87 |
| - puts "The CSS Watchr is not yet implemented." |
| 58 | + task :css do |
| 59 | + compass_compile({ |
| 60 | + :output_style => :nested, |
| 61 | + :line_comments => true |
| 62 | + }) |
88 | 63 | end
|
89 |
| -end # of namespace :css |
90 |
| -task :css => 'css:build' |
| 64 | + end |
| 65 | +end |
| 66 | + |
| 67 | + |
| 68 | +task :watch do sh 'bundle exec guard -g css js'; end |
| 69 | +namespace :watch do |
| 70 | + |
| 71 | + task :js do sh 'bundle exec guard -g js'; end |
| 72 | + task :css do sh 'bundle exec guard -g css'; end |
| 73 | + |
| 74 | + task :debug do sh 'bundle exec guard -g debug_js debug_css'; end |
| 75 | + namespace :debug do |
| 76 | + |
| 77 | + task :js do sh 'bundle exec guard -g debug_js'; end |
| 78 | + task :css do sh 'bundle exec guard -g debug_css'; end |
| 79 | + end |
| 80 | +end |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +# Helper functions |
| 85 | +def compass_compile(configs) |
| 86 | + # This code was largely inspired by this SO question |
| 87 | + # http://stackoverflow.com/questions/25399962/compass-from-ruby-sasscompiler-not-found |
| 88 | + # with addtional code and configuraion options drawn from: |
| 89 | + # https://github.com/Compass/compass/blob/350bcaa544f594bca972aaa29a9bdfddceee5d4f/cli/lib/compass/exec/global_options_parser.rb |
| 90 | + # https://github.com/Compass/compass/blob/350bcaa544f594bca972aaa29a9bdfddceee5d4f/cli/lib/compass/exec/project_options_parser.rb |
| 91 | + # NOTE(Drew): I made the choice here to start from the above SO question |
| 92 | + # and code snippets to make this call using the undocumented |
| 93 | + # Ruby API of Compass rather than building a shell call out |
| 94 | + # of a Ruby string and passing that to the OS layer. I don't |
| 95 | + # know if it's the right choice, but it's the choice I made. |
| 96 | + # Hopefully no one gets bit by it. |
| 97 | + require 'compass' |
| 98 | + require 'compass/sass_compiler' |
91 | 99 |
|
| 100 | + Compass.configuration.add_import_path "#{$css_source}/imports" |
| 101 | + configs[:project_path] = "." |
| 102 | + configs[:http_path] = "/" |
| 103 | + configs[:sass_path] = $css_source |
| 104 | + configs[:css_path] = $css_dest |
| 105 | + configs[:cache_path] = "#{$css_source}/.sass-cache" |
| 106 | + Compass.add_configuration(configs, "basho_docs_configs") |
| 107 | + compiler = Compass.sass_compiler({ |
| 108 | + :only_sass_files => Dir.glob("#{$css_source}/*.scss") |
| 109 | + }) |
| 110 | + compiler.compile! |
| 111 | +end |
0 commit comments