mwilliams-facebooker 1.0.40
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +15 -0
- data/CHANGELOG.rdoc +24 -0
- data/COPYING.rdoc +19 -0
- data/Manifest.txt +133 -0
- data/README.rdoc +113 -0
- data/Rakefile +85 -0
- data/TODO.rdoc +4 -0
- data/examples/desktop_login.rb +14 -0
- data/facebooker.gemspec +38 -0
- data/generators/facebook/facebook_generator.rb +14 -0
- data/generators/facebook/templates/config/facebooker.yml +49 -0
- data/generators/facebook/templates/public/javascripts/facebooker.js +93 -0
- data/generators/facebook_controller/USAGE +33 -0
- data/generators/facebook_controller/facebook_controller_generator.rb +40 -0
- data/generators/facebook_controller/templates/controller.rb +7 -0
- data/generators/facebook_controller/templates/functional_test.rb +11 -0
- data/generators/facebook_controller/templates/helper.rb +2 -0
- data/generators/facebook_controller/templates/view.fbml.erb +2 -0
- data/generators/facebook_controller/templates/view.html.erb +2 -0
- data/generators/facebook_publisher/facebook_publisher_generator.rb +14 -0
- data/generators/facebook_publisher/templates/create_facebook_templates.rb +15 -0
- data/generators/facebook_publisher/templates/publisher.rb +3 -0
- data/generators/facebook_scaffold/USAGE +27 -0
- data/generators/facebook_scaffold/facebook_scaffold_generator.rb +118 -0
- data/generators/facebook_scaffold/templates/controller.rb +93 -0
- data/generators/facebook_scaffold/templates/facebook_style.css +2579 -0
- data/generators/facebook_scaffold/templates/functional_test.rb +89 -0
- data/generators/facebook_scaffold/templates/helper.rb +2 -0
- data/generators/facebook_scaffold/templates/layout.fbml.erb +6 -0
- data/generators/facebook_scaffold/templates/layout.html.erb +17 -0
- data/generators/facebook_scaffold/templates/style.css +74 -0
- data/generators/facebook_scaffold/templates/view_edit.fbml.erb +13 -0
- data/generators/facebook_scaffold/templates/view_edit.html.erb +18 -0
- data/generators/facebook_scaffold/templates/view_index.fbml.erb +24 -0
- data/generators/facebook_scaffold/templates/view_index.html.erb +24 -0
- data/generators/facebook_scaffold/templates/view_new.fbml.erb +12 -0
- data/generators/facebook_scaffold/templates/view_new.html.erb +17 -0
- data/generators/facebook_scaffold/templates/view_show.fbml.erb +10 -0
- data/generators/facebook_scaffold/templates/view_show.html.erb +10 -0
- data/generators/publisher/publisher_generator.rb +14 -0
- data/generators/xd_receiver/templates/xd_receiver.html +10 -0
- data/generators/xd_receiver/xd_receiver_generator.rb +10 -0
- data/init.rb +26 -0
- data/install.rb +12 -0
- data/lib/facebooker.rb +216 -0
- data/lib/facebooker/adapters/adapter_base.rb +91 -0
- data/lib/facebooker/adapters/bebo_adapter.rb +77 -0
- data/lib/facebooker/adapters/facebook_adapter.rb +52 -0
- data/lib/facebooker/admin.rb +42 -0
- data/lib/facebooker/batch_request.rb +45 -0
- data/lib/facebooker/data.rb +57 -0
- data/lib/facebooker/feed.rb +78 -0
- data/lib/facebooker/logging.rb +44 -0
- data/lib/facebooker/mobile.rb +20 -0
- data/lib/facebooker/mock/service.rb +50 -0
- data/lib/facebooker/mock/session.rb +18 -0
- data/lib/facebooker/model.rb +139 -0
- data/lib/facebooker/models/affiliation.rb +10 -0
- data/lib/facebooker/models/album.rb +11 -0
- data/lib/facebooker/models/applicationproperties.rb +39 -0
- data/lib/facebooker/models/applicationrestrictions.rb +10 -0
- data/lib/facebooker/models/cookie.rb +10 -0
- data/lib/facebooker/models/education_info.rb +11 -0
- data/lib/facebooker/models/event.rb +28 -0
- data/lib/facebooker/models/friend_list.rb +16 -0
- data/lib/facebooker/models/group.rb +36 -0
- data/lib/facebooker/models/info_item.rb +10 -0
- data/lib/facebooker/models/info_section.rb +10 -0
- data/lib/facebooker/models/location.rb +8 -0
- data/lib/facebooker/models/notifications.rb +17 -0
- data/lib/facebooker/models/page.rb +28 -0
- data/lib/facebooker/models/photo.rb +19 -0
- data/lib/facebooker/models/tag.rb +12 -0
- data/lib/facebooker/models/user.rb +516 -0
- data/lib/facebooker/models/video.rb +9 -0
- data/lib/facebooker/models/work_info.rb +10 -0
- data/lib/facebooker/parser.rb +674 -0
- data/lib/facebooker/rails/backwards_compatible_param_checks.rb +31 -0
- data/lib/facebooker/rails/controller.rb +356 -0
- data/lib/facebooker/rails/cucumber.rb +28 -0
- data/lib/facebooker/rails/cucumber/world.rb +46 -0
- data/lib/facebooker/rails/extensions/action_controller.rb +48 -0
- data/lib/facebooker/rails/extensions/rack_setup.rb +6 -0
- data/lib/facebooker/rails/extensions/routing.rb +15 -0
- data/lib/facebooker/rails/facebook_form_builder.rb +112 -0
- data/lib/facebooker/rails/facebook_pretty_errors.rb +22 -0
- data/lib/facebooker/rails/facebook_request_fix.rb +28 -0
- data/lib/facebooker/rails/facebook_request_fix_2-3.rb +31 -0
- data/lib/facebooker/rails/facebook_session_handling.rb +68 -0
- data/lib/facebooker/rails/facebook_url_helper.rb +192 -0
- data/lib/facebooker/rails/facebook_url_rewriting.rb +60 -0
- data/lib/facebooker/rails/helpers.rb +804 -0
- data/lib/facebooker/rails/helpers/fb_connect.rb +118 -0
- data/lib/facebooker/rails/integration_session.rb +38 -0
- data/lib/facebooker/rails/profile_publisher_extensions.rb +42 -0
- data/lib/facebooker/rails/publisher.rb +550 -0
- data/lib/facebooker/rails/routing.rb +49 -0
- data/lib/facebooker/rails/test_helpers.rb +68 -0
- data/lib/facebooker/rails/utilities.rb +22 -0
- data/lib/facebooker/server_cache.rb +24 -0
- data/lib/facebooker/service.rb +102 -0
- data/lib/facebooker/session.rb +636 -0
- data/lib/facebooker/version.rb +9 -0
- data/lib/net/http_multipart_post.rb +123 -0
- data/lib/rack/facebook.rb +82 -0
- data/lib/tasks/facebooker.rake +18 -0
- data/lib/tasks/tunnel.rake +46 -0
- data/rails/init.rb +1 -0
- data/setup.rb +1585 -0
- data/templates/layout.erb +24 -0
- data/test/facebooker/adapters_test.rb +174 -0
- data/test/facebooker/admin_test.rb +102 -0
- data/test/facebooker/batch_request_test.rb +83 -0
- data/test/facebooker/data_test.rb +86 -0
- data/test/facebooker/logging_test.rb +43 -0
- data/test/facebooker/mobile_test.rb +45 -0
- data/test/facebooker/model_test.rb +133 -0
- data/test/facebooker/models/event_test.rb +15 -0
- data/test/facebooker/models/photo_test.rb +16 -0
- data/test/facebooker/models/user_test.rb +361 -0
- data/test/facebooker/rails/facebook_request_fix_2-3_test.rb +25 -0
- data/test/facebooker/rails/facebook_url_rewriting_test.rb +39 -0
- data/test/facebooker/rails/publisher_test.rb +481 -0
- data/test/facebooker/rails_integration_test.rb +1434 -0
- data/test/facebooker/server_cache_test.rb +44 -0
- data/test/facebooker/session_test.rb +652 -0
- data/test/facebooker_test.rb +951 -0
- data/test/fixtures/multipart_post_body_with_only_parameters.txt +33 -0
- data/test/fixtures/multipart_post_body_with_single_file.txt +38 -0
- data/test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt +38 -0
- data/test/net/http_multipart_post_test.rb +52 -0
- data/test/rack/facebook_test.rb +61 -0
- data/test/rails_test_helper.rb +27 -0
- data/test/test_helper.rb +74 -0
- metadata +232 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
class FacebookGenerator < Rails::Generator::Base
|
2
|
+
def manifest
|
3
|
+
record do |m|
|
4
|
+
m.file 'config/facebooker.yml', 'config/facebooker.yml'
|
5
|
+
m.file 'public/javascripts/facebooker.js', 'public/javascripts/facebooker.js'
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def banner
|
12
|
+
"Usage: #{$0} facebooker"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# The api key, secret key, and canvas page name are required to get started
|
2
|
+
# Tunnel configuration is only needed if you are going to use the facebooker:tunnel Rake tasks
|
3
|
+
# Your callback url in Facebook should be set to http://public_host:public_port
|
4
|
+
# If you're building a Facebook connect site,
|
5
|
+
# change the value of set_asset_host_to_callback_url to false
|
6
|
+
# To develop for the new profile design, add the following key..
|
7
|
+
# api: new
|
8
|
+
# remove the key or set it to anything else to use the old facebook design.
|
9
|
+
# This should only be necessary until the final version of the new profile is released.
|
10
|
+
|
11
|
+
development:
|
12
|
+
api_key:
|
13
|
+
secret_key:
|
14
|
+
canvas_page_name:
|
15
|
+
callback_url:
|
16
|
+
pretty_errors: true
|
17
|
+
set_asset_host_to_callback_url: true
|
18
|
+
tunnel:
|
19
|
+
public_host_username:
|
20
|
+
public_host:
|
21
|
+
public_port: 4007
|
22
|
+
local_port: 3000
|
23
|
+
server_alive_interval: 0
|
24
|
+
|
25
|
+
test:
|
26
|
+
api_key:
|
27
|
+
secret_key:
|
28
|
+
canvas_page_name:
|
29
|
+
callback_url:
|
30
|
+
set_asset_host_to_callback_url: true
|
31
|
+
tunnel:
|
32
|
+
public_host_username:
|
33
|
+
public_host:
|
34
|
+
public_port: 4007
|
35
|
+
local_port: 3000
|
36
|
+
server_alive_interval: 0
|
37
|
+
|
38
|
+
production:
|
39
|
+
api_key:
|
40
|
+
secret_key:
|
41
|
+
canvas_page_name:
|
42
|
+
callback_url:
|
43
|
+
set_asset_host_to_callback_url: true
|
44
|
+
tunnel:
|
45
|
+
public_host_username:
|
46
|
+
public_host:
|
47
|
+
public_port: 4007
|
48
|
+
local_port: 3000
|
49
|
+
server_alive_interval: 0
|
@@ -0,0 +1,93 @@
|
|
1
|
+
|
2
|
+
function $(element) {
|
3
|
+
if (typeof element == "string") {
|
4
|
+
element=document.getElementById(element);
|
5
|
+
}
|
6
|
+
if (element)
|
7
|
+
extend_instance(element,Element);
|
8
|
+
return element;
|
9
|
+
}
|
10
|
+
|
11
|
+
function extend_instance(instance,hash) {
|
12
|
+
for (var name in hash) {
|
13
|
+
instance[name] = hash[name];
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
var Element = {
|
18
|
+
"hide": function () {
|
19
|
+
this.setStyle("display","none")
|
20
|
+
},
|
21
|
+
"show": function () {
|
22
|
+
this.setStyle("display","block")
|
23
|
+
},
|
24
|
+
"visible": function () {
|
25
|
+
return (this.getStyle("display") != "none");
|
26
|
+
},
|
27
|
+
"toggle": function () {
|
28
|
+
if (this.visible) {
|
29
|
+
this.hide();
|
30
|
+
} else {
|
31
|
+
this.show();
|
32
|
+
}
|
33
|
+
}
|
34
|
+
};
|
35
|
+
|
36
|
+
function encodeURIComponent(str) {
|
37
|
+
if (typeof(str) == "string") {
|
38
|
+
return str.replace(/=/g,'%3D').replace(/&/g,'%26');
|
39
|
+
}
|
40
|
+
//checkboxes and radio buttons return objects instead of a string
|
41
|
+
else if(typeof(str) == "object"){
|
42
|
+
for (prop in str)
|
43
|
+
{
|
44
|
+
return str[prop].replace(/=/g,'%3D').replace(/&/g,'%26');
|
45
|
+
}
|
46
|
+
}
|
47
|
+
};
|
48
|
+
|
49
|
+
var Form = {};
|
50
|
+
Form.serialize = function(form_element) {
|
51
|
+
return $(form_element).serialize();
|
52
|
+
};
|
53
|
+
|
54
|
+
Ajax.Updater = function (container,url,options) {
|
55
|
+
this.container = container;
|
56
|
+
this.url=url;
|
57
|
+
this.ajax = new Ajax();
|
58
|
+
this.ajax.requireLogin = 1;
|
59
|
+
if (options["onSuccess"]) {
|
60
|
+
this.ajax.responseType = Ajax.JSON;
|
61
|
+
this.ajax.ondone = options["onSuccess"];
|
62
|
+
} else {
|
63
|
+
this.ajax.responseType = Ajax.FBML;
|
64
|
+
this.ajax.ondone = function(data) {
|
65
|
+
$(container).setInnerFBML(data);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
if (options["onFailure"]) {
|
69
|
+
this.ajax.onerror = options["onFailure"];
|
70
|
+
}
|
71
|
+
|
72
|
+
if (!options['parameters']) {
|
73
|
+
options['parameters'] = {}
|
74
|
+
}
|
75
|
+
|
76
|
+
// simulate other verbs over post
|
77
|
+
if (options['method']) {
|
78
|
+
options['parameters']['_method'] = options['method'];
|
79
|
+
}
|
80
|
+
|
81
|
+
this.ajax.post(url,options['parameters']);
|
82
|
+
if (options["onLoading"]) {
|
83
|
+
options["onLoading"].call()
|
84
|
+
}
|
85
|
+
};
|
86
|
+
Ajax.Request = function(url,options) {
|
87
|
+
Ajax.Updater('unused',url,options);
|
88
|
+
};
|
89
|
+
|
90
|
+
PeriodicalExecuter = function (callback, frequency) {
|
91
|
+
setTimeout(callback, frequency *1000);
|
92
|
+
setTimeout(function() { new PeriodicalExecuter(callback,frequency); }, frequency*1000);
|
93
|
+
};
|
@@ -0,0 +1,33 @@
|
|
1
|
+
Description:
|
2
|
+
Stubs out a new controller and its views. Pass the controller name, either
|
3
|
+
CamelCased or under_scored, and a list of views as arguments.
|
4
|
+
|
5
|
+
To create a controller within a module, specify the controller name as a
|
6
|
+
path like 'parent_module/controller_name'.
|
7
|
+
|
8
|
+
This generates a controller class in app/controllers, view templates in
|
9
|
+
app/views/controller_name, a helper class in app/helpers, and a functional
|
10
|
+
test suite in test/functional.
|
11
|
+
|
12
|
+
Also, it generates fbml view templates.
|
13
|
+
|
14
|
+
Example:
|
15
|
+
`./script/generate controller CreditCard open debit credit close`
|
16
|
+
|
17
|
+
Credit card controller with URLs like /credit_card/debit.
|
18
|
+
Controller: app/controllers/credit_card_controller.rb
|
19
|
+
Views: app/views/credit_card/debit.html.erb [...],
|
20
|
+
app/views/credit_card/debit.fbml.erb [...]
|
21
|
+
Helper: app/helpers/credit_card_helper.rb
|
22
|
+
Test: test/functional/credit_card_controller_test.rb
|
23
|
+
|
24
|
+
Modules Example:
|
25
|
+
`./script/generate controller 'admin/credit_card' suspend late_fee`
|
26
|
+
|
27
|
+
Credit card admin controller with URLs /admin/credit_card/suspend.
|
28
|
+
Controller: app/controllers/admin/credit_card_controller.rb
|
29
|
+
Views: app/views/admin/credit_card/debit.html.erb [...],
|
30
|
+
app/views/admin/credit_card/debit.fbml.erb [...]
|
31
|
+
Helper: app/helpers/admin/credit_card_helper.rb
|
32
|
+
Test: test/functional/admin/credit_card_controller_test.rb
|
33
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class FacebookControllerGenerator < Rails::Generator::NamedBase
|
2
|
+
def manifest
|
3
|
+
record do |m|
|
4
|
+
# Check for class naming collisions.
|
5
|
+
m.class_collisions class_path, "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper"
|
6
|
+
|
7
|
+
# Controller, helper, views, and test directories.
|
8
|
+
m.directory File.join('app/controllers', class_path)
|
9
|
+
m.directory File.join('app/helpers', class_path)
|
10
|
+
m.directory File.join('app/views', class_path, file_name)
|
11
|
+
m.directory File.join('test/functional', class_path)
|
12
|
+
|
13
|
+
# Controller class, functional test, and helper class.
|
14
|
+
m.template 'controller.rb',
|
15
|
+
File.join('app/controllers',
|
16
|
+
class_path,
|
17
|
+
"#{file_name}_controller.rb")
|
18
|
+
|
19
|
+
m.template 'functional_test.rb',
|
20
|
+
File.join('test/functional',
|
21
|
+
class_path,
|
22
|
+
"#{file_name}_controller_test.rb")
|
23
|
+
|
24
|
+
m.template 'helper.rb',
|
25
|
+
File.join('app/helpers',
|
26
|
+
class_path,
|
27
|
+
"#{file_name}_helper.rb")
|
28
|
+
|
29
|
+
# View template for each action.
|
30
|
+
actions.each do |action|
|
31
|
+
html_path = File.join('app/views', class_path, file_name, "#{action}.html.erb")
|
32
|
+
m.template 'view.html.erb', html_path,
|
33
|
+
:assigns => { :action => action, :path => html_path }
|
34
|
+
fbml_path = File.join('app/views', class_path, file_name, "#{action}.fbml.erb")
|
35
|
+
m.template 'view.fbml.erb', fbml_path,
|
36
|
+
:assigns => { :action => action, :path => fbml_path }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require File.dirname(__FILE__)+'/../../vendor/plugins/facebooker/lib/facebooker/rails/test_helpers.rb'
|
3
|
+
|
4
|
+
class <%= class_name %>ControllerTest < ActionController::TestCase
|
5
|
+
include Facebooker::Rails::TestHelpers
|
6
|
+
|
7
|
+
# Replace this with your real tests.
|
8
|
+
def test_truth
|
9
|
+
assert true
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class FacebookPublisherGenerator < Rails::Generator::NamedBase
|
2
|
+
def manifest
|
3
|
+
record do |m|
|
4
|
+
m.directory "app/models"
|
5
|
+
m.template "publisher.rb", "app/models/#{file_name}_publisher.rb"
|
6
|
+
migration_file_name="create_facebook_templates"
|
7
|
+
# unless m.migration_exists?(migration_file_name)
|
8
|
+
# THis should work, but it doesn't. So we re-implement it instead
|
9
|
+
if Dir.glob(File.join(RAILS_ROOT,"db","migrate","[0-9]*_*.rb")).grep(/[0-9]+_create_facebook_templates.rb$/).blank?
|
10
|
+
m.migration_template "create_facebook_templates.rb", "db/migrate", :migration_file_name=>migration_file_name
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateFacebookTemplates < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :facebook_templates, :force => true do |t|
|
4
|
+
t.string :template_name, :null => false
|
5
|
+
t.string :content_hash, :null => false
|
6
|
+
t.string :bundle_id, :null => true
|
7
|
+
end
|
8
|
+
add_index :facebook_templates, :template_name, :unique => true
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.down
|
12
|
+
remove_index :facebook_templates, :template_name
|
13
|
+
drop_table :facebook_templates
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Description:
|
2
|
+
Scaffolds an entire resource, from model and migration to controller and
|
3
|
+
views, along with a full test suite. The resource is ready to use as a
|
4
|
+
starting point for your restful, resource-oriented application.
|
5
|
+
|
6
|
+
Pass the name of the model, either CamelCased or under_scored, as the first
|
7
|
+
argument, and an optional list of attribute pairs.
|
8
|
+
|
9
|
+
Attribute pairs are column_name:sql_type arguments specifying the
|
10
|
+
model's attributes. Timestamps are added by default, so you don't have to
|
11
|
+
specify them by hand as 'created_at:datetime updated_at:datetime'.
|
12
|
+
|
13
|
+
You don't have to think up every attribute up front, but it helps to
|
14
|
+
sketch out a few so you can start working with the resource immediately.
|
15
|
+
|
16
|
+
For example, `scaffold post title:string body:text published:boolean`
|
17
|
+
gives you a model with those three attributes, a controller that handles
|
18
|
+
the create/show/update/destroy, forms to create and edit your posts, and
|
19
|
+
an index that lists them all, as well as a map.resources :posts
|
20
|
+
declaration in config/routes.rb.
|
21
|
+
|
22
|
+
Also, it creates Facebook view templates and functional tests.
|
23
|
+
|
24
|
+
Examples:
|
25
|
+
`./script/generate scaffold post` # no attributes, view will be anemic
|
26
|
+
`./script/generate scaffold post title:string body:text published:boolean`
|
27
|
+
`./script/generate scaffold purchase order_id:integer amount:decimal`
|
@@ -0,0 +1,118 @@
|
|
1
|
+
class Rails::Generator::Commands::Create
|
2
|
+
def register_fbml_mime_type_alias
|
3
|
+
path = destination_path('config/initializers/mime_types.rb')
|
4
|
+
content = "Mime::Type.register_alias 'text/html', :fbml"
|
5
|
+
unless File.read(path).match(Regexp.escape(content))
|
6
|
+
logger.register "text/html, :fbml"
|
7
|
+
File.open(path, 'a') { |file| file.write(content) }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
class Rails::Generator::Commands::Destroy
|
12
|
+
def register_fbml_mime_type_alias
|
13
|
+
# do nothing
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class FacebookScaffoldGenerator < Rails::Generator::NamedBase
|
18
|
+
default_options :skip_timestamps => false, :skip_migration => false
|
19
|
+
|
20
|
+
attr_reader :controller_name,
|
21
|
+
:controller_class_path,
|
22
|
+
:controller_file_path,
|
23
|
+
:controller_class_nesting,
|
24
|
+
:controller_class_nesting_depth,
|
25
|
+
:controller_class_name,
|
26
|
+
:controller_underscore_name,
|
27
|
+
:controller_singular_name,
|
28
|
+
:controller_plural_name
|
29
|
+
alias_method :controller_file_name, :controller_underscore_name
|
30
|
+
alias_method :controller_table_name, :controller_plural_name
|
31
|
+
|
32
|
+
def initialize(runtime_args, runtime_options = {})
|
33
|
+
super
|
34
|
+
|
35
|
+
@controller_name = @name.pluralize
|
36
|
+
|
37
|
+
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
|
38
|
+
@controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
|
39
|
+
@controller_singular_name=base_name.singularize
|
40
|
+
if @controller_class_nesting.empty?
|
41
|
+
@controller_class_name = @controller_class_name_without_nesting
|
42
|
+
else
|
43
|
+
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def manifest
|
48
|
+
record do |m|
|
49
|
+
# Check for class naming collisions.
|
50
|
+
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
|
51
|
+
m.class_collisions(class_path, "#{class_name}")
|
52
|
+
|
53
|
+
# Controller, helper, views, test and stylesheets directories.
|
54
|
+
m.directory(File.join('app/models', class_path))
|
55
|
+
m.directory(File.join('app/controllers', controller_class_path))
|
56
|
+
m.directory(File.join('app/helpers', controller_class_path))
|
57
|
+
m.directory(File.join('app/views', controller_class_path, controller_file_name))
|
58
|
+
m.directory(File.join('app/views/layouts', controller_class_path))
|
59
|
+
m.directory(File.join('test/functional', controller_class_path))
|
60
|
+
m.directory(File.join('test/unit', class_path))
|
61
|
+
m.directory(File.join('public/stylesheets', class_path))
|
62
|
+
|
63
|
+
for action in scaffold_views
|
64
|
+
m.template(
|
65
|
+
"view_#{action}.html.erb",
|
66
|
+
File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.erb")
|
67
|
+
)
|
68
|
+
m.template(
|
69
|
+
"view_#{action}.fbml.erb",
|
70
|
+
File.join('app/views', controller_class_path, controller_file_name, "#{action}.fbml.erb")
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Layout and stylesheet.
|
75
|
+
m.template('layout.html.erb', File.join('app/views/layouts', controller_class_path, "#{controller_file_name}.html.erb"))
|
76
|
+
m.template('layout.fbml.erb', File.join('app/views/layouts', controller_class_path, "#{controller_file_name}.fbml.erb"))
|
77
|
+
m.template('style.css', 'public/stylesheets/scaffold.css')
|
78
|
+
m.template('facebook_style.css', 'public/stylesheets/facebook_scaffold.css')
|
79
|
+
|
80
|
+
m.template(
|
81
|
+
'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
|
82
|
+
)
|
83
|
+
|
84
|
+
m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
|
85
|
+
m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
|
86
|
+
|
87
|
+
m.route_resources controller_file_name
|
88
|
+
|
89
|
+
m.dependency 'model', [name] + @args, :collision => :skip
|
90
|
+
|
91
|
+
m.register_fbml_mime_type_alias
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
protected
|
96
|
+
# Override with your own usage banner.
|
97
|
+
def banner
|
98
|
+
"Usage: #{$0} scaffold ModelName [field:type, field:type]"
|
99
|
+
end
|
100
|
+
|
101
|
+
def add_options!(opt)
|
102
|
+
opt.separator ''
|
103
|
+
opt.separator 'Options:'
|
104
|
+
opt.on("--skip-timestamps",
|
105
|
+
"Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
|
106
|
+
opt.on("--skip-migration",
|
107
|
+
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
108
|
+
end
|
109
|
+
|
110
|
+
def scaffold_views
|
111
|
+
%w[ index show new edit ]
|
112
|
+
end
|
113
|
+
|
114
|
+
def model_name
|
115
|
+
class_name.demodulize
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|