dima-restfulx 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +65 -30
- data/VERSION.yml +4 -0
- data/app_generators/rx_app/rx_app_generator.rb +25 -9
- data/app_generators/rx_app/templates/actionscript.properties +3 -3
- data/app_generators/rx_app/templates/actionscriptair.properties +3 -3
- data/app_generators/rx_app/templates/app.yaml.erb +1 -1
- data/app_generators/rx_app/templates/default_tasks.rake +5 -18
- data/app_generators/rx_app/templates/generate.rb +1 -1
- data/app_generators/rx_app/templates/index.html.erb +1 -1
- data/app_generators/rx_app/templates/mainair-app.xml +3 -3
- data/app_generators/rx_app/templates/mainapp.mxml +107 -2
- data/app_generators/rx_app/templates/project-textmate.erb +4 -4
- data/app_generators/rx_app/templates/project.properties +1 -1
- data/app_generators/rx_app/templates/projectair.properties +1 -1
- data/app_generators/rx_app/templates/restfulx.yml +61 -0
- data/lib/restfulx/active_foo.rb +0 -7
- data/lib/restfulx/active_record_tasks.rb +10 -0
- data/lib/restfulx/configuration.rb +15 -10
- data/lib/restfulx/rails/swf_helper.rb +1 -1
- data/lib/restfulx/schema_to_yaml/extensions/enumerable.rb +7 -0
- data/lib/restfulx/schema_to_yaml/settings/config.rb +16 -0
- data/lib/restfulx/schema_to_yaml/settings/core.rb +70 -0
- data/lib/restfulx/schema_to_yaml.rb +120 -0
- data/lib/restfulx/tasks.rb +68 -42
- data/lib/restfulx/uuid_helper.rb +15 -0
- data/lib/restfulx.rb +5 -28
- data/rails_generators/rx_config/USAGE +2 -1
- data/rails_generators/rx_config/rx_config_generator.rb +78 -53
- data/rails_generators/rx_config/templates/actionscript.properties +3 -3
- data/rails_generators/rx_config/templates/actionscriptair.properties +3 -3
- data/rails_generators/rx_config/templates/flex_controller.erb +4 -0
- data/rails_generators/rx_config/templates/{index.html.erb → index.erb} +2 -4
- data/rails_generators/rx_config/templates/mainair-app.xml +3 -3
- data/rails_generators/rx_config/templates/mainapp.mxml +100 -2
- data/rails_generators/rx_config/templates/project-textmate.erb +4 -4
- data/rails_generators/rx_config/templates/project.properties +1 -1
- data/rails_generators/rx_config/templates/projectair.properties +1 -1
- data/rails_generators/rx_config/templates/restfulx.erb +39 -0
- data/rails_generators/rx_config/templates/restfulx.yml +51 -4
- data/rails_generators/rx_config/templates/restfulx_tasks.rake +3 -0
- data/rails_generators/rx_config/templates/routes.erb +47 -0
- data/rails_generators/rx_controller/rx_controller_generator.rb +9 -6
- data/rails_generators/rx_controller/templates/controller.as.erb +7 -9
- data/{generators → rails_generators}/rx_main_app/USAGE +0 -0
- data/rails_generators/rx_main_app/rx_main_app_generator.rb +60 -0
- data/rails_generators/rx_main_app/templates/mainapp.mxml +129 -0
- data/rails_generators/rx_scaffold/rx_scaffold_generator.rb +89 -35
- data/rails_generators/rx_scaffold/templates/{controller.rb.erb → controllers/default.rb.erb} +29 -1
- data/rails_generators/rx_scaffold/templates/controllers/resource_controller.rb.erb +23 -0
- data/rails_generators/rx_scaffold/templates/fixtures.yml.erb +9 -5
- data/{generators/rx_scaffold/templates/component.mxml.erb → rails_generators/rx_scaffold/templates/layouts/default.erb} +75 -59
- data/rails_generators/rx_scaffold/templates/migration.rb.erb +29 -2
- data/rails_generators/rx_scaffold/templates/model.as.erb +33 -2
- data/rails_generators/rx_scaffold/templates/model.rb.erb +36 -1
- data/rails_generators/rx_yaml_scaffold/rx_yaml_scaffold_generator.rb +29 -10
- data/{generators → rxgen_generators}/rx_config/USAGE +0 -0
- data/{generators → rxgen_generators}/rx_config/rx_config_generator.rb +0 -0
- data/{generators → rxgen_generators}/rx_controller/USAGE +0 -0
- data/{generators → rxgen_generators}/rx_controller/rx_controller_generator.rb +6 -5
- data/{generators → rxgen_generators}/rx_controller/templates/assist.py +2 -2
- data/{generators → rxgen_generators}/rx_controller/templates/controller.as.erb +8 -6
- data/{generators → rxgen_generators}/rx_controller/templates/restful.py +0 -0
- data/rxgen_generators/rx_main_app/USAGE +8 -0
- data/{generators → rxgen_generators}/rx_main_app/rx_main_app_generator.rb +10 -5
- data/{generators → rxgen_generators}/rx_main_app/templates/main.py.erb +0 -0
- data/rxgen_generators/rx_main_app/templates/mainapp.mxml +136 -0
- data/{generators → rxgen_generators}/rx_scaffold/USAGE +0 -0
- data/{generators → rxgen_generators}/rx_scaffold/rx_scaffold_generator.rb +5 -4
- data/{rails_generators → rxgen_generators}/rx_scaffold/templates/component.mxml.erb +24 -52
- data/{generators → rxgen_generators}/rx_scaffold/templates/controller.py.erb +1 -1
- data/{generators → rxgen_generators}/rx_scaffold/templates/model.as.erb +0 -0
- data/{generators → rxgen_generators}/rx_scaffold/templates/model.py.erb +0 -0
- data/{generators → rxgen_generators}/rx_yaml_scaffold/USAGE +0 -0
- data/{generators → rxgen_generators}/rx_yaml_scaffold/rx_yaml_scaffold_generator.rb +0 -0
- metadata +104 -66
- data/History.txt +0 -7
- data/Manifest.txt +0 -127
- data/generators/rx_main_app/templates/mainapp.mxml +0 -35
- data/rdoc/generators/template/html/jamis.rb +0 -588
- data/test/rails/playing_around_in_a_console.txt +0 -71
@@ -18,7 +18,7 @@ module SWFHelper
|
|
18
18
|
:include_session_token => true
|
19
19
|
})
|
20
20
|
arg_order = [:id, :width, :height, :version, :express_install_swf]
|
21
|
-
js_params = ["'#{swf_url}
|
21
|
+
js_params = ["'#{swf_url}'"]
|
22
22
|
js_params += arg_order.collect {|arg| "'#{params[arg]}'" }
|
23
23
|
|
24
24
|
# Add authenticity_token and the session key to flashVars. This will only work if flashVars is a Hash or nil
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# Inspired from http://settingslogic.rubyforge.org/
|
2
|
+
# Used to read in settings from restfulx.yml for use in code generation
|
3
|
+
module SchemaToYaml
|
4
|
+
module Settings
|
5
|
+
class Core
|
6
|
+
class << self
|
7
|
+
def name
|
8
|
+
instance._settings.key?("name") ? instance.name : super
|
9
|
+
end
|
10
|
+
|
11
|
+
def reset!
|
12
|
+
@instance = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def instance
|
17
|
+
@instance ||= new
|
18
|
+
end
|
19
|
+
|
20
|
+
def method_missing(name, *args, &block)
|
21
|
+
instance.send(name, *args, &block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_accessor :_settings
|
26
|
+
|
27
|
+
def initialize(name_or_hash = Config.settings_file)
|
28
|
+
case name_or_hash
|
29
|
+
when Hash
|
30
|
+
self._settings = name_or_hash
|
31
|
+
when String, Symbol
|
32
|
+
root_path = defined?(RAILS_ROOT) ? "#{RAILS_ROOT}/config/" : ""
|
33
|
+
file_path = name_or_hash.is_a?(Symbol) ? "#{root_path}#{name_or_hash}.yml" : name_or_hash
|
34
|
+
self._settings = YAML.load(ERB.new(File.read(file_path)).result)
|
35
|
+
self._settings = _settings[RAILS_ENV] if defined?(RAILS_ENV)
|
36
|
+
else
|
37
|
+
raise ArgumentError.new("Your settings must be a hash,
|
38
|
+
a symbol representing the name of the .yml file in your config directory,
|
39
|
+
or a string representing the abosolute path to your settings file.")
|
40
|
+
end
|
41
|
+
define_settings!
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def method_missing(name, *args, &block)
|
46
|
+
raise NoMethodError.new("no configuration was specified for #{name}")
|
47
|
+
end
|
48
|
+
|
49
|
+
def define_settings!
|
50
|
+
return if _settings.nil?
|
51
|
+
_settings.each do |key, value|
|
52
|
+
case value
|
53
|
+
when Hash
|
54
|
+
instance_eval <<-"end_eval", __FILE__, __LINE__
|
55
|
+
def #{key}
|
56
|
+
@#{key} ||= self.class.new(_settings["#{key}"])
|
57
|
+
end
|
58
|
+
end_eval
|
59
|
+
else
|
60
|
+
instance_eval <<-"end_eval", __FILE__, __LINE__
|
61
|
+
def #{key}
|
62
|
+
@#{key} ||= _settings["#{key}"]
|
63
|
+
end
|
64
|
+
end_eval
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# Used for analyzing your schema and exporting a model.yml file for Rx
|
2
|
+
require "yaml"
|
3
|
+
require "erb"
|
4
|
+
require File.dirname(__FILE__) + "/schema_to_yaml/settings/config"
|
5
|
+
require File.dirname(__FILE__) + "/schema_to_yaml/settings/core"
|
6
|
+
|
7
|
+
Dir[File.dirname(__FILE__) + "/schema_to_yaml/extensions/*.rb"].each do |f|
|
8
|
+
require f
|
9
|
+
end
|
10
|
+
|
11
|
+
module SchemaToYaml
|
12
|
+
RxSettings = SchemaToYaml::Settings::Core
|
13
|
+
|
14
|
+
# SchemaToYaml.schema_to_yaml
|
15
|
+
# - set of commands that introspects your database and formats your model.yml for export
|
16
|
+
def self.schema_to_yaml
|
17
|
+
# Iterates through your database, and sets up table_arr with all columns
|
18
|
+
# - excludes schema_info/schema_migrations/and any other tables you specify in restfulx.yml
|
19
|
+
table_arr = ActiveRecord::Base.connection.tables -
|
20
|
+
%w(schema_info schema_migrations).map -
|
21
|
+
RxSettings.ignored.tables[0].split
|
22
|
+
|
23
|
+
# Excludes columns from each table
|
24
|
+
disregarded_columns = %w(id created_at updated_at) + RxSettings.ignored.fields[0].split
|
25
|
+
|
26
|
+
# Schema variable is appended to throughout, and is the variable exported to model.yml
|
27
|
+
schema = []
|
28
|
+
|
29
|
+
# Set up empty array for has_many relationships
|
30
|
+
@array_of_has_manies = []
|
31
|
+
|
32
|
+
# Iterates through each table, and checks for any database field ending in _id
|
33
|
+
table_arr.each do |table|
|
34
|
+
column_arr = ActiveRecord::Base.connection.columns(table)
|
35
|
+
column_arr.each do |col|
|
36
|
+
col_name = col.name.to_s
|
37
|
+
@array_of_has_manies << "#{col_name.gsub(/_id\b/,'')}_#{table}" if col_name[-3,3]=='_id'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
table_arr.each do |table|
|
42
|
+
# Set up empty arrays for other associations
|
43
|
+
belong_tos = []
|
44
|
+
has_manies = []
|
45
|
+
polymorphics = []
|
46
|
+
|
47
|
+
# Append table name to schema
|
48
|
+
# - project:
|
49
|
+
schema << "#{table.singularize}:\n"
|
50
|
+
column_arr = ActiveRecord::Base.connection.columns(table)
|
51
|
+
|
52
|
+
column_arr.each do |col|
|
53
|
+
col_name = col.name.to_s
|
54
|
+
|
55
|
+
# Ignore certain columns
|
56
|
+
columns_check = []
|
57
|
+
disregarded_columns.each {|dc| columns_check << col_name.include?(dc) }
|
58
|
+
|
59
|
+
# Sets up polymorphics array, we'll need to check for duplicates below
|
60
|
+
polymorphics << col_name.gsub('_id','PMCHECK').gsub('_type','PMCHECK')
|
61
|
+
|
62
|
+
# Appends each column under respective table
|
63
|
+
schema << " - #{col_name}: #{col.type}\n" unless columns_check.include?(true)
|
64
|
+
|
65
|
+
# Checks for certain column names
|
66
|
+
# - If it finds parent_id it sets up a tree_model for generation
|
67
|
+
# - If it finds _file_size it sets up attachment for generation
|
68
|
+
# - Sets up belong_tos
|
69
|
+
if col_name == 'parent_id'
|
70
|
+
schema << " - tree_model: [#{col_name.gsub(/_id\b/,'')}]\n"
|
71
|
+
elsif col_name =~ /_file_size$/
|
72
|
+
schema << " - attachment_field: [#{col_name.gsub(/_file_size$/,'')}]\n"
|
73
|
+
else
|
74
|
+
belong_tos << col_name.gsub(/_id\b/,', ') if col_name[-3,3]=='_id' && !disregarded_columns.include?(col_name)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Checks for duplicates in the polymorphics array (used for error checking)
|
79
|
+
if polymorphics.dups.size > 0
|
80
|
+
schema << " - polymorphic: [#{polymorphics.dups.first.gsub('PMCHECK','')}]\n"
|
81
|
+
@polymorphic = polymorphics.dups.first.gsub('PMCHECK','')
|
82
|
+
end
|
83
|
+
|
84
|
+
# Cleans up has many
|
85
|
+
@array_of_has_manies.each do |hm|
|
86
|
+
sanity_check = hm.gsub(/^#{table.singularize}_/,'')
|
87
|
+
if hm =~ /^#{table.singularize}_/ && table_arr.include?(sanity_check)
|
88
|
+
has_manies << hm.gsub(/^#{table.singularize}_/,'') + ', '
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Appends belong_to's to schema
|
93
|
+
if belong_tos.size > 0
|
94
|
+
belong_tos = belong_tos.delete_if {|x| x == "#{@polymorphic}, " }
|
95
|
+
last_in_array_fix = belong_tos.last
|
96
|
+
last_in_array_fix = last_in_array_fix.gsub(', ','')
|
97
|
+
belong_tos.pop
|
98
|
+
belong_tos << last_in_array_fix
|
99
|
+
schema << " - belongs_to: [#{belong_tos}]\n"
|
100
|
+
end
|
101
|
+
|
102
|
+
# Appends has_manies' to schema
|
103
|
+
if has_manies.size > 0
|
104
|
+
last_in_array_fix = has_manies.last
|
105
|
+
last_in_array_fix = last_in_array_fix.gsub(', ','')
|
106
|
+
has_manies.pop
|
107
|
+
has_manies << last_in_array_fix
|
108
|
+
schema << " - has_many: [#{has_manies}]\n"
|
109
|
+
end
|
110
|
+
|
111
|
+
schema << "\n"
|
112
|
+
end
|
113
|
+
|
114
|
+
# Writes model.yml file
|
115
|
+
yml_file = File.join(RAILS_ROOT, "db", "model.yml")
|
116
|
+
File.open(yml_file, "w") { |f| f << schema.to_s }
|
117
|
+
puts "Model.yml created at db/model.yml"
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
data/lib/restfulx/tasks.rb
CHANGED
@@ -2,54 +2,84 @@
|
|
2
2
|
require 'rake'
|
3
3
|
require 'ftools'
|
4
4
|
require 'rexml/document'
|
5
|
+
require 'activesupport'
|
5
6
|
require File.join(File.dirname(__FILE__), 'configuration')
|
6
7
|
|
7
|
-
|
8
|
+
include RestfulX::Configuration
|
8
9
|
|
9
10
|
namespace :rx do
|
10
|
-
# Compile the
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
# Compile the given Flex/AIR application
|
12
|
+
# The following options are supported:
|
13
|
+
# :executable => 'mxmlc'
|
14
|
+
# :application => nil
|
15
|
+
# :destination => 'public/bin'
|
16
|
+
# :opts => nil
|
17
|
+
# :flex_root => 'app/flex'
|
18
|
+
def compile_application(params = {})
|
19
|
+
project_name, flex_project_name, command_controller_name, base_package, base_folder,
|
20
|
+
flex_root = extract_names()
|
21
|
+
|
22
|
+
executable = params[:executable] || 'mxmlc'
|
23
|
+
application = params[:application] || get_main_application
|
24
|
+
destination = params[:destination] || 'public/bin'
|
25
|
+
opts = params[:opts] || ''
|
26
|
+
flex_root = params[:flex_root] || flex_root
|
27
|
+
|
28
|
+
compiler = get_executable(executable)
|
29
|
+
|
30
|
+
application = get_main_application unless application
|
31
|
+
project_path = File.join(APP_ROOT, flex_root, application)
|
32
|
+
target_project_path = project_path.sub(/.mxml$/, '.swf')
|
33
|
+
target_project_air_descriptor = project_path.sub(/.mxml$/, '-app.xml')
|
19
34
|
|
20
|
-
|
35
|
+
libs = Dir.glob(File.join(APP_ROOT, 'lib', '*.swc')).map {|lib| lib.gsub(' ', '\ ')}
|
21
36
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
37
|
+
additional_compiler_args = get_app_properties().elements["actionScriptProperties"].elements["compiler"].attributes["additionalCompilerArguments"]
|
38
|
+
additional_compiler_args.gsub!("../locale/", "#{APP_ROOT}/app/locale/")
|
39
|
+
|
40
|
+
cmd = "#{executable} #{opts} -library-path+=#{libs.join(',')} " << additional_compiler_args << " #{project_path.gsub(' ', '\ ')}"
|
41
|
+
puts "Compiling #{project_path}"
|
42
|
+
if system(cmd)
|
43
|
+
FileUtils.makedirs File.join(APP_ROOT, destination)
|
44
|
+
puts "Moving #{target_project_path} to " + File.join(APP_ROOT, destination)
|
45
|
+
FileUtils.mv target_project_path, File.join(APP_ROOT, destination), :force => true
|
46
|
+
if File.exist?(target_project_air_descriptor)
|
47
|
+
descriptor = File.read(target_project_air_descriptor)
|
48
|
+
descriptor_name = target_project_air_descriptor.split("/").last
|
49
|
+
app_swf = target_project_path.split("/").last
|
50
|
+
descriptor.gsub!("[This value will be overwritten by Flex Builder in the output app.xml]",
|
51
|
+
app_swf)
|
35
52
|
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
puts "Created #{APP_ROOT}/#{destination}/#{descriptor_name} descriptor."
|
53
|
+
File.open("#{APP_ROOT}/#{destination}/#{descriptor_name}", "w") do |file|
|
54
|
+
file.print descriptor
|
40
55
|
end
|
41
|
-
puts
|
42
|
-
else
|
43
|
-
puts "The application was not compiled. Check console for errors. " <<
|
44
|
-
"It is possible that '(a)mxmlc' executable was not found or there are compilation errors."
|
56
|
+
puts "Created #{APP_ROOT}/#{destination}/#{descriptor_name} descriptor."
|
45
57
|
end
|
46
|
-
|
58
|
+
puts 'Done!'
|
59
|
+
else
|
60
|
+
puts "The application was not compiled. Check console for errors. " <<
|
61
|
+
"It is possible that '(a)mxmlc' executable was not found or there are compilation errors."
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def run_air_application(params = {})
|
66
|
+
application = params[:application] || get_main_application
|
67
|
+
descriptor = params[:descriptor] || application.sub(/.mxml$/, '-app.xml')
|
68
|
+
destination = params[:destination] || 'bin-debug'
|
69
|
+
|
70
|
+
puts "Running AIR application with descriptor: #{descriptor}"
|
71
|
+
if !system("#{get_executable('adl')} #{destination}/#{descriptor}")
|
72
|
+
puts "Could not run the application with descriptor: #{destination}/#{descriptor}. Check console for errors."
|
73
|
+
end
|
47
74
|
end
|
48
75
|
|
49
76
|
# Find what the main application is based on .actionScriptProperties file
|
50
77
|
def get_main_application
|
51
|
-
|
52
|
-
|
78
|
+
get_app_properties().root.attributes['mainApplicationPath'].split("/").last
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_app_properties
|
82
|
+
REXML::Document.new(File.open(File.join(APP_ROOT, ".actionScriptProperties")))
|
53
83
|
end
|
54
84
|
|
55
85
|
# Get appropriate executable based on platform
|
@@ -63,23 +93,19 @@ namespace :rx do
|
|
63
93
|
namespace :flex do
|
64
94
|
desc "Build project swf file and move it into public/bin folder"
|
65
95
|
task :build do
|
66
|
-
|
96
|
+
compile_application()
|
67
97
|
end
|
68
98
|
end
|
69
99
|
|
70
100
|
namespace :air do
|
71
101
|
desc "Build project swf file as an AIR application and move it into bin-debug folder"
|
72
102
|
task :build do
|
73
|
-
|
103
|
+
compile_application(:destination => 'bin-debug', :opts => '+configname=air')
|
74
104
|
end
|
75
105
|
|
76
106
|
desc "Run the AIR application (if this project is configured as an AIR project)"
|
77
107
|
task :run do
|
78
|
-
|
79
|
-
puts "Running AIR application with descriptor: #{target}"
|
80
|
-
if !system("#{get_executable('adl')} bin-debug/#{target}")
|
81
|
-
puts "Could not run the application with descriptor: #{target}. Check console for errors."
|
82
|
-
end
|
108
|
+
run_air_application
|
83
109
|
end
|
84
110
|
end
|
85
111
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'uuidtools'
|
2
|
+
|
3
|
+
module RestfulX
|
4
|
+
module UUIDHelper
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
before_create :generate_uuid
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def generate_uuid
|
12
|
+
self.id = UUID.random_create.to_s.gsub("-", "") unless self.id
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/restfulx.rb
CHANGED
@@ -5,8 +5,8 @@
|
|
5
5
|
module RestfulX
|
6
6
|
|
7
7
|
# :stopdoc:
|
8
|
-
VERSION = '1.2.
|
9
|
-
FRAMEWORK_VERSION = '1.2.
|
8
|
+
VERSION = '1.2.2'
|
9
|
+
FRAMEWORK_VERSION = '1.2.2'
|
10
10
|
LIB_DIR = File.join(File.dirname(__FILE__), 'restfulx/')
|
11
11
|
# :startdoc:
|
12
12
|
|
@@ -54,9 +54,10 @@ elsif defined?(ActionController::Base)
|
|
54
54
|
# if we are not running in Merb, try to hook up Rails
|
55
55
|
Mime::Type.register_alias "application/xml", :fxml
|
56
56
|
|
57
|
-
['active_foo', 'rails/swf_helper'].each { |lib| require RestfulX::LIB_DIR + lib }
|
57
|
+
['active_foo', 'rails/swf_helper', 'schema_to_yaml'].each { |lib| require RestfulX::LIB_DIR + lib }
|
58
58
|
|
59
|
-
ActionView::Base.send :include, SWFHelper unless ActionView::Base.included_modules.include?(SWFHelper)
|
59
|
+
ActionView::Base.send :include, SWFHelper unless ActionView::Base.included_modules.include?(SWFHelper)
|
60
|
+
ActiveRecord::Migration.send :include, SchemaToYaml
|
60
61
|
|
61
62
|
# We mess with default +render+ implementation a bit to add support for expressions
|
62
63
|
# such as format.fxml { render :fxml => @foo }
|
@@ -78,24 +79,6 @@ elsif defined?(ActionController::Base)
|
|
78
79
|
end
|
79
80
|
end
|
80
81
|
end
|
81
|
-
|
82
|
-
# It is possible to pass metadata with any RestfulX model. This module adds support for
|
83
|
-
# extracting that metadata into the standard params hash.
|
84
|
-
module RxController
|
85
|
-
private
|
86
|
-
|
87
|
-
# Extract any keys named _metadata from the models in the params hash
|
88
|
-
# and put them in the root of the params hash.
|
89
|
-
def extract_metadata_from_params
|
90
|
-
metadata = {}
|
91
|
-
metadata.merge!(params.delete('_metadata')) if params.has_key?('_metadata')
|
92
|
-
params.each do |k, v|
|
93
|
-
next unless v.respond_to?(:has_key?) and v.has_key?('_metadata')
|
94
|
-
metadata.merge!(v.delete('_metadata'))
|
95
|
-
end
|
96
|
-
params.merge!(metadata) unless metadata.empty?
|
97
|
-
end
|
98
|
-
end
|
99
82
|
|
100
83
|
module ActiveRecord
|
101
84
|
# ActiveRecord named scopes are computed *before* restfulx gem gets loaded
|
@@ -108,12 +91,6 @@ elsif defined?(ActionController::Base)
|
|
108
91
|
end
|
109
92
|
end
|
110
93
|
end
|
111
|
-
|
112
|
-
ActionController::Base.send :include, RxController
|
113
|
-
ActionController::Base.send :prepend_before_filter, :extract_metadata_from_params
|
114
|
-
|
115
|
-
# temporarily disable forgery protection site-wise
|
116
|
-
ActionController::Base.allow_forgery_protection = false
|
117
94
|
elsif defined?(DataMapper)
|
118
95
|
require RestfulX::LIB_DIR + 'datamapper_foo'
|
119
96
|
elsif defined?(ActiveRecord::Base)
|
@@ -14,5 +14,6 @@ Examples:
|
|
14
14
|
# folder
|
15
15
|
`./script/generate rx_config -a` # as above but generates an AIR app
|
16
16
|
# and configuration
|
17
|
-
`./script/generate rx_config -
|
17
|
+
`./script/generate rx_config --skip-framework` # generates Flex app
|
18
|
+
# but does not fetch
|
18
19
|
# the RestfulX framework SWC.
|
@@ -11,11 +11,20 @@ class RxConfigGenerator < Rails::Generator::Base
|
|
11
11
|
:command_controller_name,
|
12
12
|
:component_names,
|
13
13
|
:application_tag,
|
14
|
-
:use_air
|
14
|
+
:use_air,
|
15
|
+
:flex_root,
|
16
|
+
:base_flex_package,
|
17
|
+
:distributed
|
15
18
|
|
16
19
|
def initialize(runtime_args, runtime_options = {})
|
17
20
|
super
|
18
|
-
@project_name, @flex_project_name, @command_controller_name, @base_package, @base_folder
|
21
|
+
@project_name, @flex_project_name, @command_controller_name, @base_package, @base_folder,
|
22
|
+
@flex_root = extract_names
|
23
|
+
|
24
|
+
@base_package = options[:base_flex_package] if options[:base_flex_package]
|
25
|
+
@base_folder = options[:base_flex_package].gsub('.', '/').gsub(/\W/, '') if options[:base_flex_package]
|
26
|
+
@flex_root = options[:flex_root] if options[:flex_root]
|
27
|
+
@distributed = options[:distributed]
|
19
28
|
|
20
29
|
# if we are updating main file only we probably want to maintain the type of project it is
|
21
30
|
if options[:main_only]
|
@@ -32,7 +41,7 @@ class RxConfigGenerator < Rails::Generator::Base
|
|
32
41
|
else
|
33
42
|
@use_air = options[:air_config]
|
34
43
|
end
|
35
|
-
|
44
|
+
|
36
45
|
if @use_air
|
37
46
|
@application_tag = 'WindowedApplication'
|
38
47
|
else
|
@@ -40,60 +49,72 @@ class RxConfigGenerator < Rails::Generator::Base
|
|
40
49
|
end
|
41
50
|
|
42
51
|
@component_names = []
|
43
|
-
if File.exists?("
|
44
|
-
@component_names = list_mxml_files("
|
52
|
+
if File.exists?("#{flex_root}/#{base_folder}/components/generated")
|
53
|
+
@component_names = list_mxml_files("#{flex_root}/#{base_folder}/components/generated")
|
45
54
|
end
|
46
55
|
end
|
47
56
|
|
48
57
|
def manifest
|
49
58
|
record do |m|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
m.
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
framework_release = RestfulX::FRAMEWORK_VERSION
|
78
|
-
framework_distribution_url = "http://restfulx.github.com/releases/restfulx-#{framework_release}.swc"
|
79
|
-
framework_destination_file = "lib/restfulx-#{framework_release}.swc"
|
80
|
-
|
81
|
-
if !options[:skip_framework] && !File.exist?(framework_destination_file)
|
82
|
-
puts "fetching #{framework_release} framework binary from: #{framework_distribution_url} ..."
|
83
|
-
open(framework_destination_file, "wb").write(open(framework_distribution_url).read)
|
84
|
-
puts "done. saved to #{framework_destination_file}"
|
85
|
-
end
|
86
|
-
|
87
|
-
m.file 'swfobject.js', 'public/javascripts/swfobject.js'
|
88
|
-
m.file 'expressInstall.swf', 'public/expressInstall.swf'
|
89
|
-
m.template 'index.html.erb', 'public/index.html'
|
90
|
-
|
91
|
-
m.dependency 'rx_controller', @args
|
59
|
+
m.file 'restfulx_tasks.rake', 'lib/tasks/restfulx_tasks.rake'
|
60
|
+
m.file 'flex.properties', '.flexProperties'
|
61
|
+
m.template 'restfulx.yml', 'config/restfulx.yml'
|
62
|
+
m.template 'restfulx.erb', 'config/initializers/restfulx.rb'
|
63
|
+
|
64
|
+
m.directory "#{flex_root}"
|
65
|
+
|
66
|
+
if @use_air
|
67
|
+
m.template 'actionscriptair.properties', '.actionScriptProperties'
|
68
|
+
m.template 'projectair.properties', '.project'
|
69
|
+
else
|
70
|
+
m.template 'actionscript.properties', '.actionScriptProperties'
|
71
|
+
m.template 'project.properties', '.project'
|
72
|
+
end
|
73
|
+
|
74
|
+
m.template 'project-textmate.erb', "#{project_name}.tmproj"
|
75
|
+
m.template 'mainapp.mxml', File.join("#{flex_root}", "#{flex_project_name}.mxml")
|
76
|
+
m.template 'mainapp-config.xml', File.join("#{flex_root}", "#{flex_project_name}-config.xml")
|
77
|
+
m.template 'mainair-app.xml', File.join("#{flex_root}", "#{flex_project_name}-app.xml") if @use_air
|
78
|
+
|
79
|
+
m.directory 'html-template/history'
|
80
|
+
%w(index.template.html AC_OETags.js playerProductInstall.swf).each do |file|
|
81
|
+
m.file "html-template/#{file}", "html-template/#{file}"
|
82
|
+
end
|
83
|
+
|
84
|
+
%w(history.css history.js historyFrame.html).each do |file|
|
85
|
+
m.file "html-template/history/#{file}", "html-template/history/#{file}"
|
92
86
|
end
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
87
|
+
|
88
|
+
%w(components controllers commands models events).each do |dir|
|
89
|
+
m.directory "#{flex_root}/#{base_folder}/#{dir}"
|
90
|
+
end
|
91
|
+
|
92
|
+
m.directory "#{flex_root}/#{base_folder}/components/generated"
|
93
|
+
|
94
|
+
framework_release = RestfulX::FRAMEWORK_VERSION
|
95
|
+
framework_distribution_url = "http://restfulx.github.com/releases/restfulx-#{framework_release}.swc"
|
96
|
+
framework_destination_file = "lib/restfulx-#{framework_release}.swc"
|
97
|
+
|
98
|
+
if !options[:skip_framework] && !File.exist?(framework_destination_file)
|
99
|
+
puts "fetching #{framework_release} framework binary from: #{framework_distribution_url} ..."
|
100
|
+
open(framework_destination_file, "wb").write(open(framework_distribution_url).read)
|
101
|
+
puts "done. saved to #{framework_destination_file}"
|
102
|
+
end
|
103
|
+
|
104
|
+
m.file 'swfobject.js', 'public/javascripts/swfobject.js'
|
105
|
+
m.file 'expressInstall.swf', 'public/expressInstall.swf'
|
106
|
+
|
107
|
+
m.file 'flex_controller.erb', 'app/controllers/flex_controller.rb'
|
108
|
+
|
109
|
+
m.directory "app/views/flex"
|
110
|
+
|
111
|
+
m.template 'index.erb', 'app/views/flex/index.html.erb'
|
112
|
+
|
113
|
+
m.file 'routes.erb', 'config/routes.rb', :collision => :force
|
114
|
+
|
115
|
+
FileUtils.rm 'public/index.html' if File.exist?('public/index.html')
|
116
|
+
|
117
|
+
m.dependency 'rx_controller', @args
|
97
118
|
end
|
98
119
|
end
|
99
120
|
|
@@ -101,12 +122,16 @@ class RxConfigGenerator < Rails::Generator::Base
|
|
101
122
|
def add_options!(opt)
|
102
123
|
opt.separator ''
|
103
124
|
opt.separator 'Options:'
|
104
|
-
opt.on("-m", "--main-only", "Only generate the main Flex/AIR application file.",
|
105
|
-
"Default: false") { |v| options[:main_only] = v }
|
106
125
|
opt.on("-a", "--air", "Configure AIR project instead of Flex. Flex is default.",
|
107
126
|
"Default: false") { |v| options[:air_config] = v }
|
108
127
|
opt.on("--skip-framework", "Don't fetch the latest framework binary. You'll have to link/build the framework yourself.",
|
109
128
|
"Default: false") { |v| options[:skip_framework] = v }
|
129
|
+
opt.on("--flex-root [FOLDER]", "Root folder for generated flex code.",
|
130
|
+
"Default: app/flex") { |v| options[:flex_root] = v }
|
131
|
+
opt.on("--base-flex-package [PACKAGE]", "Base package for your application.",
|
132
|
+
"Default: #{flex_project_name}") { |v| options[:base_flex_package] = v }
|
133
|
+
opt.on("--distributed", "Creates migrations, controllers and models that use UUIDs and are distribution ready",
|
134
|
+
"Default: false") { |v| options[:distributed] = v }
|
110
135
|
end
|
111
136
|
|
112
137
|
def banner
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<actionScriptProperties mainApplicationPath="<%=
|
3
|
-
<compiler additionalCompilerArguments="-locale en_US -keep-as3-metadata+=Resource,HasOne,HasMany,BelongsTo,DateTime,Lazy,Ignored" copyDependentFiles="true" enableModuleDebug="true" generateAccessible="false" htmlExpressInstall="true" htmlGenerate="true" htmlHistoryManagement="true" htmlPlayerVersion="9.0.28" htmlPlayerVersionCheck="true" outputFolderPath="public/bin" rootURL="http://localhost:3000/bin" sourceFolderPath="
|
2
|
+
<actionScriptProperties mainApplicationPath="<%= flex_project_name %>.mxml" version="3">
|
3
|
+
<compiler additionalCompilerArguments="-locale en_US -keep-as3-metadata+=Resource,HasOne,HasMany,BelongsTo,DateTime,Lazy,Ignored" copyDependentFiles="true" enableModuleDebug="true" generateAccessible="false" htmlExpressInstall="true" htmlGenerate="true" htmlHistoryManagement="true" htmlPlayerVersion="9.0.28" htmlPlayerVersionCheck="true" outputFolderPath="public/bin" rootURL="http://localhost:3000/bin" sourceFolderPath="<%= flex_root %>" strict="true" useApolloConfig="false" verifyDigests="true" warn="true">
|
4
4
|
<compilerSourcePath/>
|
5
5
|
<libraryPath defaultLinkType="1">
|
6
6
|
<libraryPathEntry kind="4" path=""/>
|
@@ -9,7 +9,7 @@
|
|
9
9
|
<sourceAttachmentPath/>
|
10
10
|
</compiler>
|
11
11
|
<applications>
|
12
|
-
<application path="<%=
|
12
|
+
<application path="<%= flex_project_name %>.mxml"/>
|
13
13
|
</applications>
|
14
14
|
<modules/>
|
15
15
|
<buildCSSFiles/>
|