Class: Distil::NibTask
- Inherits:
-
Task
- Object
- Configurable
- Task
- Distil::NibTask
- Includes:
- ErrorReporter
- Defined in:
- lib/distil/task/nib-task.rb
Instance Attribute Summary
Attributes inherited from Configurable
Instance Method Summary collapse
- #handles_file(file) ⇒ Object
- #include_file(file) ⇒ Object
- #preprocess_file(nib_name, nib_folder, file) ⇒ Object
Methods included from ErrorReporter
#error, error, #ignore_warnings, #ignore_warnings=, #report, warning, #warning
Methods inherited from Task
#find_files, #handles_file?, inherited, #initialize, #process_files, #project, #target, tasks
Methods inherited from Configurable
#get_option, #get_options, #initialize, option
Constructor Details
This class inherits a constructor from Distil::Task
Instance Method Details
#handles_file(file) ⇒ Object
8 9 10 |
# File 'lib/distil/task/nib-task.rb', line 8 def handles_file(file) return ["js"].include?(file.content_type) end |
#include_file(file) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/distil/task/nib-task.rb', line 41 def include_file(file) return if !File.fnmatch("**/*.jsnib/*.js", file) # puts "Nib asset: #{file}" match= file.to_s.match(/([^\.\/]+).jsnib\/(.*)\.js/) return if match[1]!=match[2] nib_name= match[1] nib_folder= File.dirname(file) preprocess_file(nib_name, nib_folder, file) # Found main js file inside the JSNib add assets for all the other files target.set_alias_for_asset("#{match[1]}##{match[2]}", file) Dir.glob("#{File.dirname(file)}/**/*") { |asset| next if File.directory?(asset) || asset.to_s==file.to_s asset= SourceFile.from_path(asset) preprocess_file(nib_name, nib_folder, asset) file.add_asset(asset) if 'html'==asset.content_type target.set_alias_for_asset("#{nib_name}##{asset.relative_to_folder(nib_folder)}", asset) end } end |
#preprocess_file(nib_name, nib_folder, file) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/distil/task/nib-task.rb', line 12 def preprocess_file(nib_name, nib_folder, file) return if !handles_file(file) content= target.get_content_for_file(file).split("\n") line_num=0 content.each { |line| line_num+=1 # handle dependencies line.gsub!(NIB_ASSET_REGEX) { |match| asset_file= File.(File.join(file.parent_folder, $2)) asset_file= SourceFile.from_path(asset_file) if (!File.exists?(asset_file)) file.warning "Asset not found: #{$2} (#{asset_file})", line_num "#{$0}" else "#{$1}(\"#{asset_file.relative_to_folder(target.source_folder)}\")" # "#{$1}(\"#{nib_name}##{asset_file.relative_to_folder(nib_folder)}\")" end } } target.set_content_for_file(file, content.join("\n")) end |