Class: Plasmoid::Haml

Inherits:
Object
  • Object
show all
Defined in:
lib/plasmoid/haml.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Haml

Returns a new instance of Haml.



5
6
7
8
9
10
11
12
# File 'lib/plasmoid/haml.rb', line 5

def initialize(path)
  @path = path
  @output_path = path.sub(/\.haml$/, "")

  if valid?
    ::Haml::Engine.new(File.read(@path)).def_method(self, :render)
  end
end

Class Method Details

.generateObject



25
26
27
28
29
# File 'lib/plasmoid/haml.rb', line 25

def self.generate
  Dir["contents/**/**/*.haml"].each do |path|
    Plasmoid::Haml.new(path).write
  end
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/plasmoid/haml.rb', line 14

def valid?
  defined?(::Haml)
end

#writeObject



18
19
20
21
22
23
# File 'lib/plasmoid/haml.rb', line 18

def write
  return if !valid?
  File.open(@output_path, "w") do |f|
    f.write(self.render)
  end
end