Permalink
Browse files

New extension generator.

  • Loading branch information...
1 parent 121d2dc commit 9bb1d9fd3efce6325c1105b3615fcae5eb2fe561 @schof schof committed Aug 4, 2010
View
@@ -1 +1 @@
-0.30.0
+0.30.0.beta1
@@ -0,0 +1,61 @@
+require 'generators/spree_core'
+require 'rails/generators/named_base'
+
+module Spree
+ module Generators
+ class ExtensionGenerator < Rails::Generators::NamedBase
+ extend Spree::Generators::TemplatePath
+
+ desc "Creates a new extension with the name you specify."
+ check_class_collision
+
+ def create_root_files
+ empty_directory file_name
+ template "LICENSE", "#{file_name}/LICENSE"
+ template "Rakefile", "#{file_name}/Rakefile"
+ template "README.md", "#{file_name}/README.md"
+ template ".gitignore", "#{file_name}/.gitignore"
+ template "extension.gemspec.tt", "#{file_name}/#{file_name.dasherize}.gemspec"
+ end
+
+ def create_app_dirs
+ empty_directory extension_dir('app')
+ empty_directory extension_dir('app/controllers')
+ empty_directory extension_dir('app/helpers')
+ empty_directory extension_dir('app/metal')
+ empty_directory extension_dir('app/models')
+ empty_directory extension_dir('app/views')
+ end
+
+ def create_config_files
+ directory "config", "#{file_name}/config"
+ #empty_directory extension_dir('config/initializers')
+ end
+
+ def create_lib_files
+ directory "lib", "#{file_name}/lib"
+ template 'extension/engine.rb.tt', "#{file_name}/lib/#{file_name}/engine.rb"
+ template 'extension/extension.rb.tt', "#{file_name}/lib/#{file_name}.rb"
+ end
+
+ def update_gemfile
+ gem file_name.dasherize, :path => file_name, :require => [file_name, "#{file_name}/engine"], :group => "extensions"
+ end
+
+ protected
+
+ def current_locale
+ I18n.locale.to_s
+ end
+
+ def extension_dir(join=nil)
+ if join
+ File.join(file_name, join)
+ else
+ file_name
+ end
+ end
+
+ end
+ end
+end
@@ -0,0 +1,23 @@
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of the Rails Dog LLC nor the names of its
+ contributors may be used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,13 @@
+<%= class_name %>
+<%= "=" * class_name.size %>
+
+Introduction goes here.
+
+
+Example
+=======
+
+Example goes here.
+
+
+Copyright (c) <%= Date.today.year %> [name of extension creator], released under the New BSD License
@@ -0,0 +1 @@
+#TODO: RAILS3 - not clear what extension Rakefile should consist of
@@ -0,0 +1 @@
+# Initializer code goes here
@@ -0,0 +1,2 @@
+---
+<%= I18n.locale.to_s %>:
@@ -0,0 +1,3 @@
+Rails.application.routes.draw do |map|
+ # add your extension routes here
+end
@@ -0,0 +1,21 @@
+Gem::Specification.new do |s|
+ s.platform = Gem::Platform::RUBY
+ s.name = %q{<%= file_name %>}
+ s.version = '1.0.0'
+ s.summary = 'Add gem summary here'
+ #s.description = 'Add (optional) gem description here'
+ s.required_ruby_version = '>= 1.8.7'
+
+ # s.author = 'David Heinemeier Hansson'
+ # s.email = 'david@loudthinking.com'
+ # s.homepage = 'http://www.rubyonrails.org'
+ # s.rubyforge_project = 'actionmailer'
+
+ s.files = Dir['CHANGELOG', 'README.md', 'LICENSE', 'lib/**/*', 'app/**/*']
+ s.require_path = 'lib'
+ s.requirements << 'none'
+
+ s.has_rdoc = true
+
+ s.add_dependency('spree_core', '>= <%= Spree.version %>')
+end
@@ -0,0 +1,14 @@
+require 'spree_core'
+require '<%=file_name %>'
+
+module <%=class_name%>
+ class Engine < Rails::Engine
+ def self.activate
+ lambda{
+ # Activation logic goes here. This should be reserved for doing class_eval on classes that are defined
+ # outside of the extension (so that monkey patches are not lost on subsequent requests in development mode.)
+ }
+ end
+ config.to_prepare &self.activate
+ end
+end
@@ -0,0 +1 @@
+# require necessary libraries files, etc. (ex. require 'extension_name/some_lib')
@@ -0,0 +1 @@
+# add custom rake tasks here
@@ -0,0 +1,9 @@
+module Spree
+ module Generators
+ module TemplatePath
+ def source_root
+ @_spree_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'spree', generator_name, 'templates'))
+ end
+ end
+ end
+end
View
@@ -31,7 +31,7 @@
require 'paperclip'
require 'stringex'
require 'will_paginate'
-require 'less'
+require 'less' #TODO RAILS3: consider making this optional
require 'authlogic'
require 'awesome_nested_set'
require 'acts_as_list'
@@ -65,4 +65,10 @@
ActiveSupport.on_load(:action_view) do
include StoreHelpers
+end
+
+module Spree
+ def self.version
+ "0.30.0.beta1"
+ end
end

0 comments on commit 9bb1d9f

Please sign in to comment.