Module: Lucky7::Builder
- Defined in:
- lib/lucky7/builder.rb
Constant Summary collapse
- SrcRegex =
/src/- BuildDirectory =
"build"
Class Method Summary collapse
- .build ⇒ Object
- .build_continuously(loop = true) ⇒ Object
- .build_haml(paths) ⇒ Object
- .build_jabs(files) ⇒ Object
- .build_path_for(extension, src_path) ⇒ Object
- .build_sass(paths) ⇒ Object
- .build_spec(paths) ⇒ Object
- .cache_mtimes! ⇒ Object
- .cached_mtimes ⇒ Object
- .ensure_build_path!(path) ⇒ Object
- .files ⇒ Object
- .files_flattened ⇒ Object
- .haml_glob ⇒ Object
- .haml_render_context ⇒ Object
- .jabs_glob ⇒ Object
- .modified_files ⇒ Object
- .mtimes ⇒ Object
- .pack ⇒ Object
- .sass_glob ⇒ Object
- .spec_glob ⇒ Object
Class Method Details
.build ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/lucky7/builder.rb', line 72 def build m = modified_files build_sass m[:sass] build_haml m[:haml] build_jabs m[:jabs] build_spec m[:spec] pack end |
.build_continuously(loop = true) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/lucky7/builder.rb', line 64 def build_continuously loop=true cache_mtimes! begin build sleep 1 if loop end while loop end |
.build_haml(paths) ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/lucky7/builder.rb', line 86 def build_haml paths paths.each do |path| file= File.new build_path_for(:html, path), 'w' haml= File.read(path) en= Haml::Engine.new(haml) html= en.render haml_render_context file.write(html) file.close end end |
.build_jabs(files) ⇒ Object
119 120 121 |
# File 'lib/lucky7/builder.rb', line 119 def build_jabs files end |
.build_path_for(extension, src_path) ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/lucky7/builder.rb', line 131 def build_path_for extension, src_path path= File.dirname(src_path).gsub(SrcRegex, BuildDirectory) src_path= src_path.split('.').first path+= "/#{File.basename(src_path)}.#{extension}" ensure_build_path! path path end |
.build_sass(paths) ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/lucky7/builder.rb', line 97 def build_sass paths paths.each do |path| file= File.new build_path_for(:css, path), 'w' sass= File.read(path) en= Sass::Engine.new(sass) css= en.render file.write(css) file.close end end |
.build_spec(paths) ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/lucky7/builder.rb', line 108 def build_spec paths paths.each do |path| file= File.new build_path_for('spec.html', path), 'w' jass= File.read(path) en= Jass::Engine.new(jass) js_spec= en.render file.write js_spec file.close end end |
.cache_mtimes! ⇒ Object
47 48 49 |
# File 'lib/lucky7/builder.rb', line 47 def cache_mtimes! @cached_mtimes = mtimes end |
.cached_mtimes ⇒ Object
51 52 53 |
# File 'lib/lucky7/builder.rb', line 51 def cached_mtimes @cached_mtimes end |
.ensure_build_path!(path) ⇒ Object
127 128 129 |
# File 'lib/lucky7/builder.rb', line 127 def ensure_build_path! path FileUtils.mkdir_p File.dirname(path) end |
.files ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/lucky7/builder.rb', line 26 def files {:haml=>haml_glob, :sass=>sass_glob, :jabs=>jabs_glob, :spec=>spec_glob}.inject({}) do |hash, pair| hash[pair.first]= Dir.glob(pair.last) hash end end |
.files_flattened ⇒ Object
36 37 38 |
# File 'lib/lucky7/builder.rb', line 36 def files_flattened files.map{|pair| pair.last}.flatten end |
.haml_glob ⇒ Object
10 11 12 |
# File 'lib/lucky7/builder.rb', line 10 def haml_glob "#{Lucky7Root}/**/*.html.haml" end |
.haml_render_context ⇒ Object
82 83 84 |
# File 'lib/lucky7/builder.rb', line 82 def haml_render_context Lucky7::Renders end |
.jabs_glob ⇒ Object
18 19 20 |
# File 'lib/lucky7/builder.rb', line 18 def jabs_glob "#{Lucky7Root}/**/*.js.jabs" end |
.modified_files ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/lucky7/builder.rb', line 55 def modified_files files.inject({}) do |hash, pair| hash[pair.first] = pair.last.select do |file| File.stat(file).mtime.to_i > cached_mtimes[file].to_i end hash end end |
.mtimes ⇒ Object
40 41 42 43 44 45 |
# File 'lib/lucky7/builder.rb', line 40 def mtimes files_flattened.inject({}) do |hash, filename| hash[filename] = File.stat(filename).mtime hash end end |
.pack ⇒ Object
123 124 125 |
# File 'lib/lucky7/builder.rb', line 123 def pack end |
.sass_glob ⇒ Object
14 15 16 |
# File 'lib/lucky7/builder.rb', line 14 def sass_glob "#{Lucky7Root}/**/*.css.sass" end |
.spec_glob ⇒ Object
22 23 24 |
# File 'lib/lucky7/builder.rb', line 22 def spec_glob "#{Lucky7Root}/**/*.html.jass" end |