Class: Plasmoid::Generator

Inherits:
Object
  • Object
show all
Includes:
TemplateHelper
Defined in:
lib/plasmoid/generator.rb,
lib/plasmoid/generator/options.rb,
lib/plasmoid/generator/template_helper.rb

Direct Known Subclasses

RubyGenerator, WebkitGenerator

Defined Under Namespace

Modules: TemplateHelper Classes: Options

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(options = {})
  self.options = options

  self.project_name   = options[:project_name]
  if self.project_name.nil? || self.project_name.squeeze.strip == ""
    raise "no name was given"
  end

  self.target_dir             = options[:directory] || self.project_name

  self.summary                = options[:summary] || 'TODO: one-line summary of your plasmoid'
  self.description            = options[:description] || 'TODO: longer description of your plasmoid'

  self.user_name       = options[:user_name]
  self.user_email      = options[:user_email]
  self.homepage        = options[:homepage]
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



17
18
19
# File 'lib/plasmoid/generator.rb', line 17

def description
  @description
end

#homepageObject

Returns the value of attribute homepage.



17
18
19
# File 'lib/plasmoid/generator.rb', line 17

def homepage
  @homepage
end

#optionsObject

Returns the value of attribute options.



16
17
18
# File 'lib/plasmoid/generator.rb', line 16

def options
  @options
end

#project_nameObject

Returns the value of attribute project_name.



17
18
19
# File 'lib/plasmoid/generator.rb', line 17

def project_name
  @project_name
end

#summaryObject

Returns the value of attribute summary.



17
18
19
# File 'lib/plasmoid/generator.rb', line 17

def summary
  @summary
end

#target_dirObject

Returns the value of attribute target_dir.



15
16
17
# File 'lib/plasmoid/generator.rb', line 15

def target_dir
  @target_dir
end

#user_emailObject

Returns the value of attribute user_email.



17
18
19
# File 'lib/plasmoid/generator.rb', line 17

def user_email
  @user_email
end

#user_nameObject

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)
  options = self::Options.new(args)

  if options[:invalid_argument]
    $stderr.puts options[:invalid_argument]
    options[:show_help] = true
  end

  if options[:show_help]
    $stderr.puts options.parser
    return 1
  end

  if options[:project_name].nil? || options[:project_name].squeeze.strip == ""
    $stderr.puts options.parser
    return 1
  end

  generator = options[:generator].new(options)
  generator.run
  return 0
end

Instance Method Details

#create_version_controlObject



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

#runObject



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