Class: Cubic::Generator::View

Inherits:
Base
  • Object
show all
Includes:
FileUtils
Defined in:
lib/cubic/generators/view.rb

Overview

View fulfils the V in the MVC pattern. The html documents generated by the View generator will sit in your app/views directory, waiting to be served by your application.

Instance Attribute Summary

Attributes inherited from Base

#files

Instance Method Summary collapse

Methods inherited from Base

#callback, #initialize

Constructor Details

This class inherits a constructor from Cubic::Generator::Base

Instance Method Details

#design(dir, action) ⇒ Object

Creates a hash that will be used for file generation purposes



12
13
14
15
16
# File 'lib/cubic/generators/view.rb', line 12

def design(dir, action)
  @files << { directory: "#{Config[:root_path]}/app/views/#{dir}",
              path: "/app/views/#{dir}/#{action}.#{Config[:html_type]}",
              content: "%p Coming to you from in #{dir}/#{action}" }
end

#generateObject



18
19
20
21
22
23
24
# File 'lib/cubic/generators/view.rb', line 18

def generate
  @files.each do |info|
    mkdir_p(info[:directory]) unless Dir.exist?(info[:directory])
    path = File.join(Config[:root_path], info[:path])
    File.open(path, 'w') { |f| f.write(info[:content]) }
  end
end