1
0
Fork 0
mirror of https://github.com/kbparagua/paloma synced 2023-03-27 23:21:17 -04:00

Handle namespaced controllers

This commit is contained in:
Bia Esmero 2013-01-03 16:39:41 +08:00
parent 9298475b02
commit 0fba57f88f
5 changed files with 43 additions and 7 deletions

View file

@ -1,6 +1,10 @@
Changelog
=
Version 1.1.0
-
* Handle namespaced controllers: `rails g paloma:add namespace/controller action`
Version 1.0.0
-
* `AddGenerator` changed from `rails g paloma:add controller/action` to `rails g paloma:add controller action`

View file

@ -3,7 +3,6 @@ TODO
Features
-
* Handle namespaced controllers
* Setup for coffescript (although I hate coffescript)
* A way to manually trigger callbacks with parameters

View file

@ -25,16 +25,21 @@ module Paloma
class AddGenerator < ::Rails::Generators::NamedBase
source_root Paloma.templates
def create_callback_file
def create_callback_file
arg = file_path.split(' ')
@controller_name = arg[0]
action_name = arg[1]
controller_folder = "#{Paloma.destination}/#{@controller_name}/"
namespace = arg[0].split('/')
namespace_folder = "#{Paloma.destination}/#{namespace[0]}" if (namespace.size > 1)
@controller_name = (namespace.size > 1) ? namespace[1] : arg[0]
controller_folder = namespace_folder.present? ? "#{namespace_folder}/#{@controller_name}" : "#{Paloma.destination}/#{@controller_name}"
callbacks_js = "#{controller_folder}/_callbacks.js"
local_js = "#{controller_folder}/_local.js"
action_js = "#{controller_folder}/#{action_name}.js"
Dir.mkdir(namespace_folder) if(namespace_folder.present? && !Dir.exists?(namespace_folder))
Dir.mkdir(controller_folder) unless Dir.exists?(controller_folder)
generate_from_template local_js unless File.exists?(local_js)
@ -48,7 +53,7 @@ module Paloma
File.open(action_js, 'w'){ |f| f.write(content) }
end
# Require controller's _callbacks.js to Paloma's main index.js file.
# Located on "#{Paloma.destination}/index.js" or by default on
# app/assets/javascripts/paloma/index.js

View file

@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'paloma'
s.version = '1.0.0'
s.version = '1.1.0'
s.summary = "a sexy way to organize javascript files using Rails` asset pipeline"
s.description = "a sexy way to organize javascript files using Rails` asset pipeline"
s.authors = ["Karl Paragua", "Bia Esmero"]

View file

@ -116,3 +116,31 @@ feature Paloma::AddGenerator, 'creating both controller folder and action file'
}
end
end
feature Paloma::AddGenerator, 'creating namespaced controller folder and action file' do
include GeneratorSpec::TestCase
destination TEMP
arguments ['namespace/new_controller_folder new_action']
before do
prepare_destination
mimic_setup
run_generator
end
specify do
destination_root.should have_structure {
directory Paloma.destination do
directory 'namespace' do
directory 'new_controller_folder' do
file 'new_action.js' do
contains "Paloma.callbacks['new_controller_folder/new_action']"
end
end
end
end
}
end
end