Class: Plasmoid::Generator
- Inherits:
-
Object
- Object
- Plasmoid::Generator
- Includes:
- TemplateHelper
- Defined in:
- lib/plasmoid/generator.rb,
lib/plasmoid/generator/options.rb,
lib/plasmoid/generator/template_helper.rb
Direct Known Subclasses
Defined Under Namespace
Modules: TemplateHelper Classes: Options
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#homepage ⇒ Object
Returns the value of attribute homepage.
-
#options ⇒ Object
Returns the value of attribute options.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#target_dir ⇒ Object
Returns the value of attribute target_dir.
-
#user_email ⇒ Object
Returns the value of attribute user_email.
-
#user_name ⇒ Object
Returns the value of attribute user_name.
Class Method Summary collapse
Instance Method Summary collapse
- #create_version_control ⇒ Object
-
#initialize(options = {}) ⇒ Generator
constructor
A new instance of Generator.
- #run ⇒ Object
Methods included from TemplateHelper
included, #mkdir, #prefix_dir, #render_template, #template_dir, #write_template
Constructor Details
#initialize(options = {}) ⇒ Generator
Returns a new instance of Generator.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/plasmoid/generator.rb', line 19 def initialize( = {}) self. = self.project_name = [:project_name] if self.project_name.nil? || self.project_name.squeeze.strip == "" raise "no name was given" end self.target_dir = [:directory] || self.project_name self.summary = [:summary] || 'TODO: one-line summary of your plasmoid' self.description = [:description] || 'TODO: longer description of your plasmoid' self.user_name = [:user_name] self.user_email = [:user_email] self.homepage = [:homepage] end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
17 18 19 |
# File 'lib/plasmoid/generator.rb', line 17 def description @description end |
#homepage ⇒ Object
Returns the value of attribute homepage.
17 18 19 |
# File 'lib/plasmoid/generator.rb', line 17 def homepage @homepage end |
#options ⇒ Object
Returns the value of attribute options.
16 17 18 |
# File 'lib/plasmoid/generator.rb', line 16 def @options end |
#project_name ⇒ Object
Returns the value of attribute project_name.
17 18 19 |
# File 'lib/plasmoid/generator.rb', line 17 def project_name @project_name end |
#summary ⇒ Object
Returns the value of attribute summary.
17 18 19 |
# File 'lib/plasmoid/generator.rb', line 17 def summary @summary end |
#target_dir ⇒ Object
Returns the value of attribute target_dir.
15 16 17 |
# File 'lib/plasmoid/generator.rb', line 15 def target_dir @target_dir end |
#user_email ⇒ Object
Returns the value of attribute user_email.
17 18 19 |
# File 'lib/plasmoid/generator.rb', line 17 def user_email @user_email end |
#user_name ⇒ Object
Returns the value of attribute user_name.
17 18 19 |
# File 'lib/plasmoid/generator.rb', line 17 def user_name @user_name end |
Class Method Details
.run!(*args) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/plasmoid/generator.rb', line 37 def self.run!(*args) = self::Options.new(args) if [:invalid_argument] $stderr.puts [:invalid_argument] [:show_help] = true end if [:show_help] $stderr.puts .parser return 1 end if [:project_name].nil? || [:project_name].squeeze.strip == "" $stderr.puts .parser return 1 end generator = [:generator].new() generator.run return 0 end |
Instance Method Details
#create_version_control ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/plasmoid/generator.rb', line 66 def create_version_control Dir.chdir(target_dir) do begin @repo = Git.init() rescue Git::GitExecuteError => e raise "Encountered an error during gitification. Maybe the repo already exists, or has already been pushed to?" end begin @repo.add('.') rescue Git::GitExecuteError => e raise end begin @repo.commit "Initial commit to #{project_name}." rescue Git::GitExecuteError => e end end end |
#run ⇒ Object
60 61 62 63 64 |
# File 'lib/plasmoid/generator.rb', line 60 def run create_files create_version_control $stdout.puts "Your plasmoid is ready at #{target_dir}\ntype `rake -T` to see the available actions" end |