Class: K4slide::Tasks::K4slideTasks
- Inherits:
-
Object
- Object
- K4slide::Tasks::K4slideTasks
- Includes:
- Rake::DSL
- Defined in:
- lib/k4slide/tasks.rb
Instance Method Summary collapse
-
#example_markdown_targets ⇒ Object
Compiling example markdown file.
- #get_closure_sources ⇒ FileList
- #get_sass_source ⇒ FileList
-
#initialize ⇒ K4slideTasks
constructor
A new instance of K4slideTasks.
- #install(&block) ⇒ Object
Constructor Details
#initialize ⇒ K4slideTasks
Returns a new instance of K4slideTasks.
17 18 19 |
# File 'lib/k4slide/tasks.rb', line 17 def initialize @compiler = nil end |
Instance Method Details
#example_markdown_targets ⇒ Object
Compiling example markdown file
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/k4slide/tasks.rb', line 128 def example_markdown_targets() target_files = [] example_dir = File.join(K4_ROOT, 'example') ext = 'md' filelist = FileList[File.join(example_dir, "*.#{ext}")] filelist.each do |source_path| source_basename = File.basename(source_path) next if source_basename =~ /^_/ source_basename = source_basename.gsub(/#{ext}$/, 'html') target_path = File.join(example_dir, source_basename) # File.delete(target_path) if File.exists?(target_path) file(target_path) do |t, args| puts t.name src = File.read(source_path) compiler_ = MarkdownCompiler.new(@compiler) html_source = compiler_.(src) File.open(target_path, 'w') do |io| io.write(html_source) end end target_files << target_path end return target_files end |
#get_closure_sources ⇒ FileList
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/k4slide/tasks.rb', line 50 def get_closure_sources target_files = [] source_dir = @config.closure.target_dir compiled_dir = @config.closure.compiled_dir depends_files = [] @config.closure.load_paths << source_dir @config.closure.load_paths.each do |load_path| depends_files += FileList[File.join(load_path, '**/*.js')].flatten if load_path end ns_suffix = @config.closure.namespace_suffix || 'App' filelist = FileList[File.join(source_dir, '*.js')] filelist.each do |source_path| source_basename = File.basename(source_path) target_path = File.join(compiled_dir, source_basename) same_name_dir = source_path.gsub(/\.js$/, '') depends = depends_files.dup depends.unshift(FileList[File.join(same_name_dir, '**/*.js')].flatten) depends.unshift(source_path) depends = depends.flatten file(target_path => depends) do |t, args| basename = File.basename(t.name).gsub(/\.js$/, '') namespace = "#{basename}.#{ns_suffix}" js_source = @compiler.closure.compile(namespace) File.open(target_path, 'w') do |io| io.write(js_source) end end target_files << target_path end return target_files end |
#get_sass_source ⇒ FileList
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/k4slide/tasks.rb', line 89 def get_sass_source() target_files = [] source_dir = @config.scss.target_dir compiled_dir = @config.scss.compiled_dir ext = @config.scss.ext || 'scss' @config.scss.load_paths << source_dir depends_files = [] @config.scss.load_paths.each do |load_path| depends_files += FileList[File.join(load_path, "**/*.#{ext}")].flatten if load_path end filelist = FileList[File.join(source_dir, "*.#{ext}")] filelist.each do |source_path| source_basename = File.basename(source_path) next if source_basename =~ /^_/ source_basename = source_basename.gsub(/#{ext}$/, 'css') target_path = File.join(compiled_dir, source_basename) depends = depends_files.dup depends.unshift(source_path) file(target_path => depends) do |t, args| puts t.name src = File.read(source_path) css_source = @compiler.scss.compile(src) File.open(target_path, 'w') do |io| io.write(css_source) end end target_files << target_path end return target_files end |
#install(&block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/k4slide/tasks.rb', line 21 def install(&block) @compiler = ::K4compiler.setup(&block) @config = @compiler.config namespace :k4s do namespace :compile do desc 'Compile JavaScript source with Closure Library.' task :closure => get_closure_sources() desc 'Compile SASS sources' task :sass => get_sass_source() desc 'Compile Markdown sources' task :markdown do puts "Compile Markdown" end desc 'Compile sources.' task :all => ['k4s:compile:closure', 'k4s:compile:sass', 'k4s:compile:markdown'] end namespace :example do task :md2s => (['k4s:example:compile'] + example_markdown_targets()) task :compile => ['k4s:compile:all'] end end end |