Class: Boss::PostGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/boss/post_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ PostGenerator

Returns a new instance of PostGenerator.



4
5
6
7
8
9
# File 'lib/boss/post_generator.rb', line 4

def initialize(*args)
  @html = "<%# This file was generated, please do not edit unless you are sure of what you're doing %>\n\n<% post ||= @post %>\n\n"
  yield.each do |elem|
    send elem
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/boss/post_generator.rb', line 20

def method_missing(method, *args)
  begin
    file = File.open("#{Boss::Engine.root}/app/views/boss/posts/_#{method.to_s}.html.erb", "rb")
    @html += file.read
    @html += "\n"
    file.close
  rescue
    super
  end
end

Instance Method Details

#generateObject



11
12
13
14
15
16
17
18
# File 'lib/boss/post_generator.rb', line 11

def generate
  begin
    file = File.open("#{Boss::Engine.root}/app/views/boss/posts/show.html.erb", "wb")
    file.write @html
  ensure
    file.close
  end
end