Module: Webgen::Task::CreateBundle
- Defined in:
- lib/webgen/task/create_bundle.rb
Overview
Creates an extension bundle.
An extension bundle is a collection of webgen extensions. This task can either create a local bundle (in the ext
directory of the current website) or a bundle which can be distributed via Rubygems.
Constant Summary collapse
- TEMPLATE_DIR =
'bundle_template_files'
Class Method Summary collapse
-
.call(website, name, type, directory = name) ⇒ Object
Create an extension bundle with the given name and of the given type (either :local or :gem).
-
.create_directory(dir) ⇒ Object
:nodoc:.
-
.create_distribution_bundle(website, directory, bundle_name) ⇒ Object
:nodoc:.
-
.create_file(dest, source, bundle_name) ⇒ Object
:nodoc:.
-
.create_local_bundle(website, bundle_name) ⇒ Object
:nodoc:.
Class Method Details
.call(website, name, type, directory = name) ⇒ Object
Create an extension bundle with the given name and of the given type (either :local or :gem).
If the type is :gem, the directory in which the bundle should be created can optionally be specified.
Returns true
if the bundle has been created.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/webgen/task/create_bundle.rb', line 26 def self.call(website, name, type, directory = name) dir = if type == :gem create_distribution_bundle(website, directory, name) else create_local_bundle(website, name) end website.logger.info { "Bundle '#{name}' of type '#{type}' created at <#{dir}>" } true end |
.create_directory(dir) ⇒ Object
:nodoc:
58 59 60 61 |
# File 'lib/webgen/task/create_bundle.rb', line 58 def self.create_directory(dir) #:nodoc: raise "The directory '#{dir}' does already exist" if File.exist?(dir) FileUtils.mkdir_p(dir) end |
.create_distribution_bundle(website, directory, bundle_name) ⇒ Object
:nodoc:
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/webgen/task/create_bundle.rb', line 37 def self.create_distribution_bundle(website, directory, bundle_name) #:nodoc: bundle_dir = File.join(directory, 'lib', 'webgen', 'bundle', bundle_name) create_directory(directory) create_directory(bundle_dir) create_file(File.join(directory, 'Rakefile'), 'Rakefile.erb', bundle_name) create_file(File.join(directory, 'README.md'), 'README.md.erb', bundle_name) create_file(File.join(bundle_dir, 'info.yaml'), 'info.yaml.erb', bundle_name) create_file(File.join(bundle_dir, 'init.rb'), 'init.rb.erb', bundle_name) directory end |
.create_file(dest, source, bundle_name) ⇒ Object
:nodoc:
63 64 65 66 67 68 |
# File 'lib/webgen/task/create_bundle.rb', line 63 def self.create_file(dest, source, bundle_name) #:nodoc: File.open(dest, 'w+') do |f| erb = ERB.new(File.read(File.join(Webgen::Utils.data_dir, TEMPLATE_DIR, source))) f.write(erb.result(binding)) end end |
.create_local_bundle(website, bundle_name) ⇒ Object
:nodoc:
49 50 51 52 53 54 55 56 |
# File 'lib/webgen/task/create_bundle.rb', line 49 def self.create_local_bundle(website, bundle_name) #:nodoc: bundle_dir = File.join(website.directory, 'ext', bundle_name) create_directory(bundle_dir) create_file(File.join(bundle_dir, 'info.yaml'), 'info.yaml.erb', bundle_name) create_file(File.join(bundle_dir, 'init.rb'), 'init.rb.erb', bundle_name) bundle_dir end |