Skip to content

Commit

Permalink
New --skip-frontend option for refinery:engine generator
Browse files Browse the repository at this point in the history
It will skip all frontend stuff (views, controller, routes, adding a new
page and also it skips some links in admin views)
  • Loading branch information
simi committed Feb 2, 2012
1 parent 079b9ca commit 18f8d90
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 2 deletions.
10 changes: 9 additions & 1 deletion core/lib/generators/refinery/engine/engine_generator.rb
Expand Up @@ -8,6 +8,7 @@ class EngineGenerator < Rails::Generators::NamedBase
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
class_option :namespace, :type => :string, :default => nil, :banner => 'NAMESPACE', :required => false
class_option :engine, :type => :string, :default => nil, :banner => 'ENGINE', :required => false
class_option :skip_frontend, :type => :boolean, :default => false, :required => false, :desc => 'Generate engine without frontend'
remove_class_option :skip_namespace

def namespacing
Expand Down Expand Up @@ -50,6 +51,10 @@ def engine_plural_name
end
end

def skip_frontend?
options[:skip_frontend]
end

def generate
destination_pathname = Pathname.new(self.destination_root)
clash_file = Pathname.new(File.expand_path('../clash_keywords.yml', __FILE__))
Expand All @@ -72,7 +77,7 @@ def generate
end

unless attributes.empty? and self.behavior != :revoke
Pathname.glob(Pathname.new(self.class.source_root).join('**', '**')).reject{|f| f.directory?}.sort.each do |path|
Pathname.glob(Pathname.new(self.class.source_root).join('**', '**')).reject{|f| f.directory? or reject_file?(f) }.sort.each do |path|
unless (engine_path = engine_path_for(path, engine_name)).nil?
template path, engine_path
end
Expand Down Expand Up @@ -178,5 +183,8 @@ def engine_path_for(path, engine)
path
end

def reject_file?(file)
skip_frontend? and (file.to_s.include?('app') and not file.to_s.scan(/admin|models/).any?)
end
end
end
Expand Up @@ -4,9 +4,11 @@
<span class="preview">&nbsp;</span>
</span>
<span class='actions'>
<% unless skip_frontend? %>
<%%= link_to refinery_icon_tag("application_go.png"), refinery.<%= namespacing.underscore %>_<%= singular_name %>_path(<%= singular_name %>),
:title => t('.view_live_html'),
:target => "_blank" %>
<% end %>
<%%= link_to refinery_icon_tag("application_edit.png"), refinery.edit_<%= namespacing.underscore %>_admin_<%= singular_name %>_path(<%= singular_name %>),
:title => t('.edit') %>
<%%= link_to refinery_icon_tag("delete.png"), refinery.<%= namespacing.underscore %>_admin_<%= singular_name %>_path(<%= singular_name %>),
Expand Down
@@ -1,8 +1,11 @@
<<<<<<< HEAD
Refinery::Core::Engine.routes.draw do
<% unless skip_frontend? %>
# Frontend routes
namespace :<%= namespacing.underscore %>: do
resources :<%= class_name.pluralize.underscore.downcase %>, :only => [:index, :show]
end
<% end %>
# Admin routes
namespace :<%= namespacing.underscore %>, :path => '' do
Expand Down
Expand Up @@ -25,10 +25,11 @@ def down
::Refinery::UserPlugin.destroy_all({:name => "<%= class_name.pluralize.underscore.downcase %>"})
end

<% unless skip_frontend? %>
if defined?(::Refinery::Page)
::Refinery::Page.delete_all({:link_url => "/<%= plural_name %>"})
end

<% end %>
drop_table :refinery_<%= "#{namespacing.underscore}_" if table_name != namespacing.underscore.pluralize -%><%= table_name %>
end

Expand Down
Expand Up @@ -7,6 +7,7 @@
end
end

<% unless skip_frontend? %>
if defined?(::Refinery::Page) && ::Refinery::Page.where(:link_url => '/<%= plural_name %>').empty?
page = ::Refinery::Page.create(
:title => '<%= class_name.pluralize.underscore.titleize %>',
Expand All @@ -19,3 +20,4 @@
page.parts.create(:title => default_page_part, :body => nil)
end
end
<% end %>
@@ -0,0 +1,74 @@
require 'spec_helper'
require 'generator_spec/test_case'
require 'generators/refinery/engine/engine_generator'

module Refinery
describe EngineGenerator do
include GeneratorSpec::TestCase
destination File.expand_path("../../../../../../tmp", __FILE__)

before(:each) do
prepare_destination
run_generator %w{ rspec_product_test title:string description:text image:image brochure:resource --skip-frontend }
end

specify do
destination_root.should have_structure {
directory "vendor" do
directory "engines" do
directory "rspec_product_tests" do
directory "app" do
directory "controllers" do
directory "refinery" do
directory "rspec_product_tests" do
directory "admin" do
file "rspec_product_tests_controller.rb"
end
no_file "rspec_product_tests_controller.rb"
end
end
end
directory "models" do
directory "refinery" do
directory "rspec_product_tests" do
file "rspec_product_test.rb"
end
end
end
directory "views" do
directory "refinery" do
directory "rspec_product_tests" do
directory "admin" do
directory "rspec_product_tests" do
file "_form.html.erb"
file "_sortable_list.html.erb"
file "edit.html.erb"
file "index.html.erb"
file "new.html.erb"
file "_rspec_product_test.html.erb"
end
end
directory "rspec_product_tests" do
no_file "index.html.erb"
no_file "show.html.erb"
end
end
end
end
end
directory "lib" do
file "refinerycms-rspec_product_tests.rb"
end
directory "config" do
directory "locales" do
file "en.yml"
end
file "routes.rb"
end
end
end
end
}
end
end
end

0 comments on commit 18f8d90

Please sign in to comment.