Class: Zfben_libjs::Source
- Inherits:
-
Object
- Object
- Zfben_libjs::Source
- Defined in:
- lib/zfben_libjs/source.rb
Instance Attribute Summary collapse
-
#compiled ⇒ Object
Returns the value of attribute compiled.
-
#filepath ⇒ Object
Returns the value of attribute filepath.
-
#minified ⇒ Object
Returns the value of attribute minified.
-
#options ⇒ Object
Returns the value of attribute options.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #compile ⇒ Object
- #download! ⇒ Object
-
#initialize(*opts) ⇒ Source
constructor
A new instance of Source.
- #minify ⇒ Object
- #name ⇒ Object
- #remote? ⇒ Boolean
- #type ⇒ Object
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
#compiled ⇒ Object
Returns the value of attribute compiled.
16 17 18 |
# File 'lib/zfben_libjs/source.rb', line 16 def compiled @compiled end |
#filepath ⇒ Object
Returns the value of attribute filepath.
16 17 18 |
# File 'lib/zfben_libjs/source.rb', line 16 def filepath @filepath end |
#minified ⇒ Object
Returns the value of attribute minified.
16 17 18 |
# File 'lib/zfben_libjs/source.rb', line 16 def minified @minified end |
#options ⇒ Object
Returns the value of attribute options.
16 17 18 |
# File 'lib/zfben_libjs/source.rb', line 16 def @options end |
#source ⇒ Object
Returns the value of attribute source.
16 17 18 |
# File 'lib/zfben_libjs/source.rb', line 16 def source @source end |
Instance Method Details
#compile ⇒ Object
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 |
#minify ⇒ Object
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 |
#name ⇒ Object
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
32 33 34 |
# File 'lib/zfben_libjs/source.rb', line 32 def remote? return /^https?:\/\// =~ @filepath end |
#type ⇒ Object
50 51 52 |
# File 'lib/zfben_libjs/source.rb', line 50 def type self.class.to_s.gsub(/Zfben_libjs::/, '').downcase end |