Class: Slickr::Generators::Base
- Inherits:
-
Object
- Object
- Slickr::Generators::Base
- Defined in:
- lib/slickr/generators/base.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#copy_file(filename, path = "") ⇒ Object
Copy a file from ROOT/files to somewhere in the project directory.
-
#empty_directory(path) ⇒ Object
Create an empty directory at
pathinside the project. -
#initialize(name) ⇒ Base
constructor
A new instance of Base.
-
#template(filename, path) ⇒ Object
Render an erb template at a specific path within the project.
Constructor Details
#initialize(name) ⇒ Base
Returns a new instance of Base.
7 8 9 10 |
# File 'lib/slickr/generators/base.rb', line 7 def initialize(name) @name = name @destination = Pathname.new(Dir.pwd) end |
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination.
5 6 7 |
# File 'lib/slickr/generators/base.rb', line 5 def destination @destination end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/slickr/generators/base.rb', line 4 def name @name end |
Instance Method Details
#copy_file(filename, path = "") ⇒ Object
Copy a file from ROOT/files to somewhere in the project directory.
This does not render anything, it’s just a simple cp.
38 39 40 41 42 |
# File 'lib/slickr/generators/base.rb', line 38 def copy_file(filename, path="") source = root.join("files", filename) dest = destination.join(path, filename) FileUtils.cp(source, dest) end |
#empty_directory(path) ⇒ Object
Create an empty directory at path inside the project.
19 20 21 |
# File 'lib/slickr/generators/base.rb', line 19 def empty_directory(path) destination.join(with_correct_path_seperator(path)).mkpath end |
#template(filename, path) ⇒ Object
Render an erb template at a specific path within the project.
Renders ERB in the context of the class calling this method. Meaning you’ll need to make whatever variables you want in your template available within the class. See Actions::Create, name is an accessor and used in the template.
58 59 60 61 62 |
# File 'lib/slickr/generators/base.rb', line 58 def template(filename, path) file = lib_file(with_correct_path_seperator(path)) file.dirname.mkpath file.open("w+") { |f| f << render(template_root(filename)) } end |