restfulx 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +123 -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 +25 -0
- data/bin/rx-gen +1 -1
- data/lib/restfulx/active_foo.rb +0 -8
- data/lib/restfulx/active_record_tasks.rb +9 -0
- data/lib/restfulx/active_record_uuid_helper.rb +17 -0
- data/lib/restfulx/configuration.rb +19 -31
- data/lib/restfulx/rails/schema_to_yaml/extensions/enumerable.rb +8 -0
- data/lib/restfulx/rails/schema_to_yaml/settings/config.rb +17 -0
- data/lib/restfulx/rails/schema_to_yaml/settings/core.rb +70 -0
- data/lib/restfulx/rails/schema_to_yaml.rb +121 -0
- data/lib/restfulx/rails/swf_helper.rb +1 -6
- data/lib/restfulx/tasks.rb +68 -42
- data/lib/restfulx.rb +4 -35
- data/rails_generators/rx_config/USAGE +2 -1
- data/rails_generators/rx_config/rx_config_generator.rb +80 -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 +38 -0
- data/rails_generators/rx_config/templates/restfulx.yml +55 -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/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 +88 -34
- 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_controller/rx_controller_generator.rb +7 -5
- data/{generators → rxgen_generators}/rx_controller/templates/assist.py +3 -3
- data/{generators → rxgen_generators}/rx_controller/templates/controller.as.erb +8 -6
- data/rxgen_generators/rx_controller/templates/iso8601.py +92 -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/rxgen_generators/rx_main_app/templates/mainapp.mxml +152 -0
- data/{generators → rxgen_generators}/rx_scaffold/rx_scaffold_generator.rb +6 -5
- data/{rails_generators → rxgen_generators}/rx_scaffold/templates/component.mxml.erb +24 -52
- data/spec/restfulx_spec.rb +1 -4
- data/spec/spec_helper.rb +0 -3
- data/tasks/restfulx.rake +2 -0
- metadata +102 -81
- 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/tasks/ann.rake +0 -80
- data/tasks/bones.rake +0 -20
- data/tasks/gem.rake +0 -201
- data/tasks/git.rake +0 -40
- data/tasks/manifest.rake +0 -48
- data/tasks/notes.rake +0 -27
- data/tasks/post_load.rake +0 -39
- data/tasks/rdoc.rake +0 -50
- data/tasks/rubyforge.rake +0 -55
- data/tasks/setup.rb +0 -279
- data/tasks/spec.rake +0 -54
- data/tasks/svn.rake +0 -47
- data/tasks/test.rake +0 -40
- data/test/rails/playing_around_in_a_console.txt +0 -71
- /data/{generators → rails_generators}/rx_main_app/USAGE +0 -0
- /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/templates/restful.py +0 -0
- /data/{generators → rxgen_generators}/rx_main_app/templates/main.py.erb +0 -0
- /data/{generators → rxgen_generators}/rx_scaffold/USAGE +0 -0
- /data/{generators → rxgen_generators}/rx_scaffold/templates/controller.py.erb +0 -0
- /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
|
@@ -13,54 +13,42 @@ class String
|
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
# Primary RestfulX configuration options
|
|
16
17
|
module RestfulX
|
|
17
18
|
# Computes necessary configuration options from the environment. This can be used in Rails, Merb
|
|
18
19
|
# or standalone from the command line.
|
|
19
20
|
module Configuration
|
|
21
|
+
# We try to figure out the application root using a number of possible options
|
|
20
22
|
APP_ROOT = defined?(RAILS_ROOT) ? RAILS_ROOT : defined?(Merb) ? Merb.root : File.expand_path(".")
|
|
21
23
|
|
|
22
|
-
# Extract project, package, controller
|
|
23
|
-
# config/restfulx.yml if it exists, you can override all of the defaults there.
|
|
24
|
-
# - *base-package* same as project name downcased
|
|
25
|
-
# - *controller-name* 'ApplicationController'
|
|
26
|
-
#
|
|
27
|
-
# Here's a sample restfulx.yml file:
|
|
28
|
-
#
|
|
29
|
-
# RestfulX code generation configuration options
|
|
30
|
-
#
|
|
31
|
-
# By default flex models, commands, controllers and components are genearated into
|
|
32
|
-
# app/flex/<your rails project name> folder. If you'd like to customize the target folder
|
|
33
|
-
# (to say append a "com" package before your rails project name) uncomment the line below
|
|
34
|
-
# base-package must follow the usual flex package notation (a string separated by ".")
|
|
35
|
-
#
|
|
36
|
-
# base-package: com.pomodo
|
|
37
|
-
#
|
|
38
|
-
# Main RestfulX controller is typically named AppicationController. This controller is created in
|
|
39
|
-
# <base-package>.controllers folder. You can customize the name by uncommenting the following line
|
|
40
|
-
# and changing the controller name.
|
|
41
|
-
#
|
|
42
|
-
# controller-name: ApplicationController
|
|
24
|
+
# Extract project, package, controller name, etc from the environment. This will respect
|
|
25
|
+
# config/restfulx.yml if it exists, you can override all of the defaults there.
|
|
43
26
|
def extract_names(project = nil)
|
|
44
27
|
if project
|
|
45
|
-
project_name = project.
|
|
46
|
-
|
|
28
|
+
project_name = project.downcase.gsub(/\W/, '')
|
|
29
|
+
flex_project_name = project_name.camelize
|
|
47
30
|
else
|
|
48
|
-
project_name = APP_ROOT.split("/").last.
|
|
49
|
-
|
|
31
|
+
project_name = APP_ROOT.split("/").last.gsub(/\W/, '')
|
|
32
|
+
flex_project_name = project_name.camelize
|
|
50
33
|
end
|
|
51
|
-
|
|
34
|
+
|
|
52
35
|
# give a chance to override the settings via restfulx.yml
|
|
53
36
|
begin
|
|
54
37
|
config = YAML.load(File.open("#{APP_ROOT}/config/restfulx.yml"))
|
|
55
|
-
base_package = config['base-package'] ||
|
|
56
|
-
base_folder = base_package.gsub('.', '/')
|
|
57
|
-
project_name = config['project-name'].
|
|
38
|
+
base_package = config['base-package'] || flex_project_name.downcase
|
|
39
|
+
base_folder = base_package.gsub('.', '/')
|
|
40
|
+
project_name = config['project-name'].downcase.gsub(/\W/, '') || project_name
|
|
41
|
+
flex_project_name = project_name.camelize
|
|
58
42
|
controller_name = config['controller-name'] || "ApplicationController"
|
|
43
|
+
flex_root = config['flex-root'] || "app/flex"
|
|
44
|
+
distributed = config['distributed'] || false
|
|
59
45
|
rescue
|
|
60
|
-
base_folder = base_package =
|
|
46
|
+
base_folder = base_package = flex_project_name.downcase
|
|
61
47
|
controller_name = "ApplicationController"
|
|
48
|
+
flex_root = "app/flex"
|
|
49
|
+
distributed = false
|
|
62
50
|
end
|
|
63
|
-
[project_name,
|
|
51
|
+
[project_name, flex_project_name, controller_name, base_package, base_folder, flex_root, distributed]
|
|
64
52
|
end
|
|
65
53
|
|
|
66
54
|
# List files ending in *.as (ActionScript) in a given folder
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# SchemaToYaml settings
|
|
2
|
+
module SchemaToYaml
|
|
3
|
+
module Settings
|
|
4
|
+
class Config
|
|
5
|
+
class << self
|
|
6
|
+
def configure
|
|
7
|
+
yield self
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def settings_file
|
|
11
|
+
@settings_file ||= :restfulx
|
|
12
|
+
end
|
|
13
|
+
attr_writer :settings_file
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -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,121 @@
|
|
|
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
|
+
# Provides facilities to convert an existing Rails application schema.rb file to
|
|
12
|
+
# RestfulX model.yml file
|
|
13
|
+
module SchemaToYaml
|
|
14
|
+
RxSettings = SchemaToYaml::Settings::Core
|
|
15
|
+
|
|
16
|
+
# SchemaToYaml.schema_to_yaml
|
|
17
|
+
# - set of commands that introspects your database and formats your model.yml for export
|
|
18
|
+
def self.schema_to_yaml
|
|
19
|
+
# Iterates through your database, and sets up table_arr with all columns
|
|
20
|
+
# - excludes schema_info/schema_migrations/and any other tables you specify in restfulx.yml
|
|
21
|
+
table_arr = ActiveRecord::Base.connection.tables -
|
|
22
|
+
%w(schema_info schema_migrations).map -
|
|
23
|
+
RxSettings.ignored.tables[0].split
|
|
24
|
+
|
|
25
|
+
# Excludes columns from each table
|
|
26
|
+
disregarded_columns = %w(id created_at updated_at) + RxSettings.ignored.fields[0].split
|
|
27
|
+
|
|
28
|
+
# Schema variable is appended to throughout, and is the variable exported to model.yml
|
|
29
|
+
schema = []
|
|
30
|
+
|
|
31
|
+
# Set up empty array for has_many relationships
|
|
32
|
+
@array_of_has_manies = []
|
|
33
|
+
|
|
34
|
+
# Iterates through each table, and checks for any database field ending in _id
|
|
35
|
+
table_arr.each do |table|
|
|
36
|
+
column_arr = ActiveRecord::Base.connection.columns(table)
|
|
37
|
+
column_arr.each do |col|
|
|
38
|
+
col_name = col.name.to_s
|
|
39
|
+
@array_of_has_manies << "#{col_name.gsub(/_id\b/,'')}_#{table}" if col_name[-3,3]=='_id'
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
table_arr.each do |table|
|
|
44
|
+
# Set up empty arrays for other associations
|
|
45
|
+
belong_tos = []
|
|
46
|
+
has_manies = []
|
|
47
|
+
polymorphics = []
|
|
48
|
+
|
|
49
|
+
# Append table name to schema
|
|
50
|
+
# - project:
|
|
51
|
+
schema << "#{table.singularize}:\n"
|
|
52
|
+
column_arr = ActiveRecord::Base.connection.columns(table)
|
|
53
|
+
|
|
54
|
+
column_arr.each do |col|
|
|
55
|
+
col_name = col.name.to_s
|
|
56
|
+
|
|
57
|
+
# Ignore certain columns
|
|
58
|
+
columns_check = []
|
|
59
|
+
disregarded_columns.each {|dc| columns_check << col_name.include?(dc) }
|
|
60
|
+
|
|
61
|
+
# Sets up polymorphics array, we'll need to check for duplicates below
|
|
62
|
+
polymorphics << col_name.gsub('_id','PMCHECK').gsub('_type','PMCHECK')
|
|
63
|
+
|
|
64
|
+
# Appends each column under respective table
|
|
65
|
+
schema << " - #{col_name}: #{col.type}\n" unless columns_check.include?(true)
|
|
66
|
+
|
|
67
|
+
# Checks for certain column names
|
|
68
|
+
# - If it finds parent_id it sets up a tree_model for generation
|
|
69
|
+
# - If it finds _file_size it sets up attachment for generation
|
|
70
|
+
# - Sets up belong_tos
|
|
71
|
+
if col_name == 'parent_id'
|
|
72
|
+
schema << " - tree_model: [#{col_name.gsub(/_id\b/,'')}]\n"
|
|
73
|
+
elsif col_name =~ /_file_size$/
|
|
74
|
+
schema << " - attachment_field: [#{col_name.gsub(/_file_size$/,'')}]\n"
|
|
75
|
+
else
|
|
76
|
+
belong_tos << col_name.gsub(/_id\b/,', ') if col_name[-3,3]=='_id' && !disregarded_columns.include?(col_name)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Checks for duplicates in the polymorphics array (used for error checking)
|
|
81
|
+
if polymorphics.dups.size > 0
|
|
82
|
+
schema << " - polymorphic: [#{polymorphics.dups.first.gsub('PMCHECK','')}]\n"
|
|
83
|
+
@polymorphic = polymorphics.dups.first.gsub('PMCHECK','')
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Cleans up has many
|
|
87
|
+
@array_of_has_manies.each do |hm|
|
|
88
|
+
sanity_check = hm.gsub(/^#{table.singularize}_/,'')
|
|
89
|
+
if hm =~ /^#{table.singularize}_/ && table_arr.include?(sanity_check)
|
|
90
|
+
has_manies << hm.gsub(/^#{table.singularize}_/,'') + ', '
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Appends belong_to's to schema
|
|
95
|
+
if belong_tos.size > 0
|
|
96
|
+
belong_tos = belong_tos.delete_if {|x| x == "#{@polymorphic}, " }
|
|
97
|
+
last_in_array_fix = belong_tos.last
|
|
98
|
+
last_in_array_fix = last_in_array_fix.gsub(', ','')
|
|
99
|
+
belong_tos.pop
|
|
100
|
+
belong_tos << last_in_array_fix
|
|
101
|
+
schema << " - belongs_to: [#{belong_tos}]\n"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Appends has_manies' to schema
|
|
105
|
+
if has_manies.size > 0
|
|
106
|
+
last_in_array_fix = has_manies.last
|
|
107
|
+
last_in_array_fix = last_in_array_fix.gsub(', ','')
|
|
108
|
+
has_manies.pop
|
|
109
|
+
has_manies << last_in_array_fix
|
|
110
|
+
schema << " - has_many: [#{has_manies}]\n"
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
schema << "\n"
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Writes model.yml file
|
|
117
|
+
yml_file = File.join(RAILS_ROOT, "db", "model.yml")
|
|
118
|
+
File.open(yml_file, "w") { |f| f << schema.to_s }
|
|
119
|
+
puts "Model.yml created at db/model.yml"
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# Adds a little helper to make it easier empbedding SWFs in ERB templates.
|
|
2
2
|
module SWFHelper
|
|
3
|
-
|
|
4
3
|
# Creates a swfObject Javascript call. You must include swfobject.js to use this.
|
|
5
4
|
# See http://code.google.com/p/swfobject/wiki/documentation for full details and documentation
|
|
6
5
|
# of the swfobject js library.
|
|
@@ -18,7 +17,7 @@ module SWFHelper
|
|
|
18
17
|
:include_session_token => true
|
|
19
18
|
})
|
|
20
19
|
arg_order = [:id, :width, :height, :version, :express_install_swf]
|
|
21
|
-
js_params = ["'#{swf_url}
|
|
20
|
+
js_params = ["'#{swf_url}'"]
|
|
22
21
|
js_params += arg_order.collect {|arg| "'#{params[arg]}'" }
|
|
23
22
|
|
|
24
23
|
# Add authenticity_token and the session key to flashVars. This will only work if flashVars is a Hash or nil
|
|
@@ -29,9 +28,6 @@ module SWFHelper
|
|
|
29
28
|
# flashVars['authenticity_token'] = <%= form_authenticity_token -%>
|
|
30
29
|
# flashVars['session_token'] = <%= session.session_id -%>
|
|
31
30
|
# </script>
|
|
32
|
-
# If you include an authenticity_token parameter in flashVars,
|
|
33
|
-
# then the Flex app will add it to Rx.defaultMetadata, so that it will be sent
|
|
34
|
-
# back up to your Rails app with every request.
|
|
35
31
|
params[:flash_vars] ||= {}
|
|
36
32
|
if params[:flash_vars].is_a?(Hash)
|
|
37
33
|
if params[:include_authenticity_token] && ActionController::Base.allow_forgery_protection
|
|
@@ -56,5 +52,4 @@ module SWFHelper
|
|
|
56
52
|
swf_tag += content_tag(:div, nil, :id => params[:id]) if params[:create_div]
|
|
57
53
|
swf_tag
|
|
58
54
|
end
|
|
59
|
-
|
|
60
55
|
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
|
data/lib/restfulx.rb
CHANGED
|
@@ -5,17 +5,10 @@
|
|
|
5
5
|
module RestfulX
|
|
6
6
|
|
|
7
7
|
# :stopdoc:
|
|
8
|
-
|
|
9
|
-
FRAMEWORK_VERSION = '1.2.1'
|
|
8
|
+
FRAMEWORK_VERSION = '1.2.2'
|
|
10
9
|
LIB_DIR = File.join(File.dirname(__FILE__), 'restfulx/')
|
|
11
10
|
# :startdoc:
|
|
12
11
|
|
|
13
|
-
# Returns the version string for the library.
|
|
14
|
-
#
|
|
15
|
-
def self.version
|
|
16
|
-
VERSION
|
|
17
|
-
end
|
|
18
|
-
|
|
19
12
|
# Utility method used to require all files ending in .rb that lie in the
|
|
20
13
|
# directory below this file that has the same name as the filename passed
|
|
21
14
|
# in. Optionally, a specific _directory_ name can be passed in such that
|
|
@@ -28,7 +21,6 @@ module RestfulX
|
|
|
28
21
|
|
|
29
22
|
Dir.glob(search_me).sort.each {|rb| require rb}
|
|
30
23
|
end
|
|
31
|
-
|
|
32
24
|
end
|
|
33
25
|
|
|
34
26
|
require RestfulX::LIB_DIR + 'configuration'
|
|
@@ -54,9 +46,10 @@ elsif defined?(ActionController::Base)
|
|
|
54
46
|
# if we are not running in Merb, try to hook up Rails
|
|
55
47
|
Mime::Type.register_alias "application/xml", :fxml
|
|
56
48
|
|
|
57
|
-
['active_foo', 'rails/swf_helper'].each { |lib| require RestfulX::LIB_DIR + lib }
|
|
49
|
+
['active_foo', 'rails/swf_helper', 'rails/schema_to_yaml'].each { |lib| require RestfulX::LIB_DIR + lib }
|
|
58
50
|
|
|
59
|
-
ActionView::Base.send :include, SWFHelper unless ActionView::Base.included_modules.include?(SWFHelper)
|
|
51
|
+
ActionView::Base.send :include, SWFHelper unless ActionView::Base.included_modules.include?(SWFHelper)
|
|
52
|
+
ActiveRecord::Migration.send :include, SchemaToYaml
|
|
60
53
|
|
|
61
54
|
# We mess with default +render+ implementation a bit to add support for expressions
|
|
62
55
|
# such as format.fxml { render :fxml => @foo }
|
|
@@ -78,24 +71,6 @@ elsif defined?(ActionController::Base)
|
|
|
78
71
|
end
|
|
79
72
|
end
|
|
80
73
|
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
74
|
|
|
100
75
|
module ActiveRecord
|
|
101
76
|
# ActiveRecord named scopes are computed *before* restfulx gem gets loaded
|
|
@@ -108,12 +83,6 @@ elsif defined?(ActionController::Base)
|
|
|
108
83
|
end
|
|
109
84
|
end
|
|
110
85
|
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
86
|
elsif defined?(DataMapper)
|
|
118
87
|
require RestfulX::LIB_DIR + 'datamapper_foo'
|
|
119
88
|
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.
|