Class: Assette::Reader::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/assette/reader.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Base

Returns a new instance of Base.



23
24
25
# File 'lib/assette/reader.rb', line 23

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



22
23
24
# File 'lib/assette/reader.rb', line 22

def file
  @file
end

Class Method Details

.extensionObject



49
50
51
52
53
# File 'lib/assette/reader.rb', line 49

def extension
  if m = self.inspect.match(/::(\w+)$/i)
    m[1].downcase
  end
end

.inherited(subclass) ⇒ Object

Gets called twice currenlty, once on Class.new(Reader::Base) and once on the subclassing. Gotta fix that



39
40
41
42
43
44
45
46
47
# File 'lib/assette/reader.rb', line 39

def inherited subclass
  return if subclass == Assette::Reader::Base || subclass.inspect =~ /#<Class/
  
  if outputs
    Assette::Reader::OUTPUTS[outputs] |= [subclass]
  end
  
  subclass.set_extension
end

.mime_typeObject



86
87
88
# File 'lib/assette/reader.rb', line 86

def mime_type
  @mime_type ||= MIME::Types.type_for("test.#{extension}").first
end

.outputsObject



55
56
57
# File 'lib/assette/reader.rb', line 55

def outputs
  
end

.set_extension(val = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/assette/reader.rb', line 70

def set_extension val = nil
  if val
    raise ArgumentError, 'must set extension to a symbol' unless val.is_a?(Symbol)
    instance_eval <<-RUBY
    def extension
      #{val.inspect}
    end
    RUBY
  end
  
  if ex = extension
    Assette::Reader::ALL[ex] = self
    Assette::Reader::OUTPUT_MAP[ex] = outputs.to_s
  end
end

.set_outputs(val) ⇒ Object

Raises:

  • (ArgumentError)


59
60
61
62
63
64
65
66
67
68
# File 'lib/assette/reader.rb', line 59

def set_outputs val
  raise ArgumentError, 'must set outputs to a symbol' unless val.is_a?(Symbol)
  
  instance_eval <<-RUBY
  def outputs
    #{val.inspect}
  end
  RUBY
  val
end

Instance Method Details

#compileObject

Raises:

  • (Exception)


31
32
33
# File 'lib/assette/reader.rb', line 31

def compile
  raise Exception, "You must implement the compile method for #{self.class.inspect}"
end

#textObject



27
28
29
# File 'lib/assette/reader.rb', line 27

def text
  @file.text
end