Class: CssDryer2::FilesHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/css_dryer_2/files_handler.rb

Overview

This module is included in rake task or anywhere (for example ApplicationController of Rails app) you need to choose when and which files are compiled.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ FilesHandler

Returns a new instance of FilesHandler.


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/css_dryer_2/files_handler.rb', line 11

def initialize(params = {})

@force_compile = false

  if params[:settings] == :rails
    @source_path   = "#{RAILS_ROOT}/public/stylesheets/ncss"
    @compile_path  = "#{RAILS_ROOT}/public/stylesheets"
    @tmp_path      = "#{RAILS_ROOT}/tmp"
  end

  @source_path   = params[:source_path]   if params[:source_path] 
  @compile_path  = params[:compile_path]  if params[:compile_path]
  @tmp_path      ||= params[:tmp_path]      || Dir.tmpdir + '/css_dryer_2_gem/tmp'
  

  unless @source_path or @compile_path or @tmp_path
    raise "You have to set source_path, compile_path and tmp_path"
  end

  FileUtils.mkdir_p(@tmp_path + '/css_dryer_2') unless File.exist?(@tmp_path + '/css_dryer_2')
end

Instance Attribute Details

#compile_pathObject

Returns the value of attribute compile_path


9
10
11
# File 'lib/css_dryer_2/files_handler.rb', line 9

def compile_path
  @compile_path
end

#force_compileObject

Returns the value of attribute force_compile


9
10
11
# File 'lib/css_dryer_2/files_handler.rb', line 9

def force_compile
  @force_compile
end

#source_pathObject

Returns the value of attribute source_path


9
10
11
# File 'lib/css_dryer_2/files_handler.rb', line 9

def source_path
  @source_path
end

#tmp_pathObject

Returns the value of attribute tmp_path


9
10
11
# File 'lib/css_dryer_2/files_handler.rb', line 9

def tmp_path
  @tmp_path
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:


39
40
41
# File 'lib/css_dryer_2/files_handler.rb', line 39

def self.configure   
  yield(self)
end

Instance Method Details

#run(params = {}) ⇒ Object


33
34
35
36
37
# File 'lib/css_dryer_2/files_handler.rb', line 33

def run(params = {})
  files = Dir.new(@source_path + '/').entries
  files.delete_if { |f| !File.file?(@source_path + "/#{f}") or !(f =~ /.ncss$/) }
  files.each { |f| prepare_file(f, params[:force_compile] || @force_compile) }
end