Class: Zfben_libjs::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/zfben_libjs/source.rb

Direct Known Subclasses

Coffee, Css, Js, Rb, Sass, Scss

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*opts) ⇒ Source

Returns a new instance of Source.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/zfben_libjs/source.rb', line 18

def initialize *opts
  [:filepath, :source, :options].each do |name|
    self.send(name.to_s + '=',  opts[0][name]) if opts[0].has_key?(name)
  end

  @options = {} if @options.nil?

  download! if remote?

  @source = @source || File.read(@filepath)

  after_initialize if self.respond_to?(:after_initialize)
end

Instance Attribute Details

#compiledObject

Returns the value of attribute compiled.



16
17
18
# File 'lib/zfben_libjs/source.rb', line 16

def compiled
  @compiled
end

#filepathObject

Returns the value of attribute filepath.



16
17
18
# File 'lib/zfben_libjs/source.rb', line 16

def filepath
  @filepath
end

#minifiedObject

Returns the value of attribute minified.



16
17
18
# File 'lib/zfben_libjs/source.rb', line 16

def minified
  @minified
end

#optionsObject

Returns the value of attribute options.



16
17
18
# File 'lib/zfben_libjs/source.rb', line 16

def options
  @options
end

#sourceObject

Returns the value of attribute source.



16
17
18
# File 'lib/zfben_libjs/source.rb', line 16

def source
  @source
end

Instance Method Details

#compileObject



54
55
56
57
58
# File 'lib/zfben_libjs/source.rb', line 54

def compile
  print "compile #{@filepath}\n" unless @filepath.nil?
  before_compile if self.respond_to?(:before_compile)
  @compiled = @compiled || @source
end

#download!Object



36
37
38
39
40
# File 'lib/zfben_libjs/source.rb', line 36

def download!
  @remote_path = @filepath
  @filepath = File.join(@options['src/source'], '.download', File.basename(@remote_path))
  download @remote_path, @filepath
end

#minifyObject



60
61
62
63
64
65
# File 'lib/zfben_libjs/source.rb', line 60

def minify
  print "minify #{@filepath}\n" unless @filepath.nil?
  before_minify if self.respond_to?(:before_minify)
  @minified = @minified || @compiled || @source
  @minified = @minified.gsub(/\n/ , '')
end

#nameObject



42
43
44
45
46
47
48
# File 'lib/zfben_libjs/source.rb', line 42

def name
  unless @filepath.nil?
    File.basename(@filepath, File.extname(@filepath))
  else
    nil
  end
end

#remote?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/zfben_libjs/source.rb', line 32

def remote?
  return /^https?:\/\// =~ @filepath
end

#typeObject



50
51
52
# File 'lib/zfben_libjs/source.rb', line 50

def type
  self.class.to_s.gsub(/Zfben_libjs::/, '').downcase
end