Class: Nucleon::Action::Plugin::Create
- Inherits:
-
Object
- Object
- Nucleon::Action::Plugin::Create
- Includes:
- Mixin::Action::Registration
- Defined in:
- lib/nucleon/action/plugin/create.rb
Class Method Summary collapse
-
.describe ⇒ Object
—————————————————————————– Info.
Instance Method Summary collapse
- #arguments ⇒ Object
- #configure ⇒ Object
-
#execute ⇒ Object
—————————————————————————– Operations.
-
#ignore ⇒ Object
—.
-
#strict? ⇒ Boolean
—————————————————————————– Settings.
Class Method Details
.describe ⇒ Object
Info
12 13 14 15 |
# File 'lib/nucleon/action/plugin/create.rb', line 12 def self.describe Nucleon.dump_enabled = true super(:plugin, :create, 10) end |
Instance Method Details
#arguments ⇒ Object
66 67 68 |
# File 'lib/nucleon/action/plugin/create.rb', line 66 def arguments [ :type, :name ] end |
#configure ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/nucleon/action/plugin/create.rb', line 24 def configure super do codes :no_template_file, :template_file_parse_failed, :plugin_already_exists, :plugin_save_failed register_str :type, :action do |value| namespace = nil components = value.to_s.split(':::') if components.size > 1 namespace = components[0].to_sym value = components[1] end value = value.to_sym Nucleon.namespaces.each do |plugin_namespace| if ! namespace || namespace == plugin_namespace if Nucleon.types(plugin_namespace).include?(value) @plugin_namespace = plugin_namespace @plugin_type = value end end end @plugin_namespace ? true : false end register_array :name, nil register_bool :save register_bool :interpolate register_directory :template_path end end |
#execute ⇒ Object
Operations
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/nucleon/action/plugin/create.rb', line 73 def execute super do |node, network| ensure_network(network) do require 'erubis' type = settings[:type].to_sym name = settings[:name] unless template_path = settings.delete(:template_path) template_path = File.join(File.dirname(__FILE__), 'template') end templates = Dir.glob("#{template_path}/**/*.erb") template = nil templates.each do |template_file| if template_file =~ /#{@plugin_namespace}\.#{@plugin_type}\.erb/ template = template_file end end if template template_contents = Util::Disk.read(template) unless template_contents error("Template file #{template} for #{@plugin_namespace}.#{@plugin_type} could not be parsed", { :i18n => false }) myself.status = code.template_file_parse_failed next end template = template_contents end unless template error("No template file exists for #{template_path}#{File::SEPARATOR}#{@plugin_namespace}.#{@plugin_type}.erb", { :i18n => false }) myself.status = code.no_template_file next end save_path = File.join(network.directory, 'lib', @plugin_namespace.to_s, @plugin_type.to_s) save_file = File.join(save_path, name.join(File::SEPARATOR) + '.rb') plugin_file = nil if File.exists?(save_file) error("Plugin already exists at #{save_file}", { :i18n => false }) myself.status = code.plugin_already_exists next end settings.import({ :plugin_class => name.pop, :plugin_groups => name }) renderer = Erubis::Eruby.new(template) parse = true while(parse) begin plugin_file = renderer.result(settings.export) parse = false rescue NameError => error settings.set(error.name, nil) rescue => error raise error end end if settings.delete(:save) # Save template to file within network project save_directory = File.dirname(save_file) FileUtils.mkdir_p(save_directory) if Util::Disk.write(save_file, plugin_file) success("Plugin successfully saved to #{save_file}", { :i18n => false }) else error("Plugin can not be saved to #{save_file}", { :i18n => false }) myself.status = code.plugin_save_failed end else info("Plugin: #{blue(save_file)}", { :i18n => false }) # Render template ONLY (testing) if settings.delete(:interpolate) puts green(plugin_file) else puts green(template) end end end end end |
#ignore ⇒ Object
62 63 64 |
# File 'lib/nucleon/action/plugin/create.rb', line 62 def ignore node_ignore end |
#strict? ⇒ Boolean
Settings
20 21 22 |
# File 'lib/nucleon/action/plugin/create.rb', line 20 def strict? false # Allow extra settings end |