Class: Trekky::Source

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

Direct Known Subclasses

HamlSource, SassSource, StaticSource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, path) ⇒ Source

Returns a new instance of Source.



7
8
9
10
11
# File 'lib/trekky/source.rb', line 7

def initialize(context, path)
  @path = path
  @context = context
  @errors = []
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/trekky/source.rb', line 5

def context
  @context
end

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/trekky/source.rb', line 5

def errors
  @errors
end

#outputObject (readonly)

Returns the value of attribute output.



5
6
7
# File 'lib/trekky/source.rb', line 5

def output
  @output
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/trekky/source.rb', line 5

def path
  @path
end

Instance Method Details

#add_error(error) ⇒ Object



33
34
35
36
37
# File 'lib/trekky/source.rb', line 33

def add_error(error)
  STDOUT.puts "ERROR: #{error.message} (#{path})"
  @errors << error
  nil
end

#clear_errorsObject



39
40
41
# File 'lib/trekky/source.rb', line 39

def clear_errors
  @errors = []
end

#extensionObject



25
26
27
# File 'lib/trekky/source.rb', line 25

def extension
  File.extname(path)
end

#inputObject



29
30
31
# File 'lib/trekky/source.rb', line 29

def input
  File.read(path)
end

#render(&block) ⇒ Object

Raises:

  • (NotImplementedError)


13
14
15
# File 'lib/trekky/source.rb', line 13

def render(&block)
  raise NotImplementedError
end

#render_error(error) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/trekky/source.rb', line 49

def render_error(error)
  Haml::Engine.new("    %h1 File: \#{path}\n    %h3 Error: \#{error.message}\n    %pre\n      %code\n        - error.backtrace.each do |line|\n          = line\n          %br\n  INPUT\nend\n".gsub(" "*8, "")).render(self, {error: error})

#render_errorsObject



43
44
45
46
47
# File 'lib/trekky/source.rb', line 43

def render_errors
  @errors.map do |error|
    render_error(error)
  end.join("<br/>")
end

#typeObject



21
22
23
# File 'lib/trekky/source.rb', line 21

def type
  extension[1..-1].intern
end

#valid?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/trekky/source.rb', line 17

def valid?
  @errors.empty?
end