Class: Stylio::Generators::Component
- Inherits:
-
Object
- Object
- Stylio::Generators::Component
- Defined in:
- lib/stylio/generators/component.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #fullpath(extension) ⇒ Object
- #generate ⇒ Object
-
#initialize(name) ⇒ Component
constructor
A new instance of Component.
Constructor Details
#initialize(name) ⇒ Component
Returns a new instance of Component.
7 8 9 |
# File 'lib/stylio/generators/component.rb', line 7 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/stylio/generators/component.rb', line 5 def name @name end |
Instance Method Details
#fullpath(extension) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/stylio/generators/component.rb', line 11 def fullpath(extension) if extension == 'html.erb' "components/#{name}/_#{name}.#{extension}" else "components/#{name}/#{name}.#{extension}" end end |
#generate ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/stylio/generators/component.rb', line 19 def generate puts "Generating component with name #{name}".yellow FileUtils::mkdir_p "components/#{name}" puts "Created folder components/#{name}".green File.open(fullpath('yml'), 'w') do |f| f.write('') end puts "Created file #{fullpath('yml')}".green File.open(fullpath('html.erb'), 'w') do |f| f.write('') end puts "Created file #{fullpath('html.erb')}".green puts "Generated component with name #{name}".green end |