flex_scaffold 0.1.0
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/CHANGELOG +4 -0
- data/MIT-LICENSE +20 -0
- data/README +169 -0
- data/Rakefile +116 -0
- data/TODO +23 -0
- data/generators/flex_scaffold/USAGE +16 -0
- data/generators/flex_scaffold/flex_scaffold_generator.rb +434 -0
- data/generators/flex_scaffold/templates/_form.rhtml +1 -0
- data/generators/flex_scaffold/templates/_index.rmxml +210 -0
- data/generators/flex_scaffold/templates/_list.rhtml +0 -0
- data/generators/flex_scaffold/templates/_list.rmxml +17 -0
- data/generators/flex_scaffold_resource/USAGE +36 -0
- data/generators/flex_scaffold_resource/flex_scaffold_resource_generator.rb +81 -0
- data/generators/flex_scaffold_resource/templates/controller.rb +101 -0
- data/generators/flex_scaffold_resource/templates/index.rhtml +3 -0
- data/generators/flex_scaffold_resource/templates/layout.rhtml +19 -0
- data/init.rb +29 -0
- data/install.rb +1 -0
- data/lib/action_view_helper.rb +49 -0
- data/lib/actionscript_helper.rb +81 -0
- data/lib/config.rb +49 -0
- data/lib/flex_scaffold_plugin.rb +25 -0
- data/lib/flexobject_view_helper.rb +132 -0
- data/lib/mtag_helper.rb +98 -0
- data/lib/mxml_helper.rb +107 -0
- data/lib/rest_scaffolding.rb +137 -0
- data/lib/validations.rb +180 -0
- data/public/crossdomain.xml +6 -0
- data/public/history.htm +21 -0
- data/public/history.swf +0 -0
- data/public/images/add.gif +0 -0
- data/public/images/arrow_down.gif +0 -0
- data/public/images/arrow_up.gif +0 -0
- data/public/images/create.gif +0 -0
- data/public/images/delete.gif +0 -0
- data/public/images/indicator-small.gif +0 -0
- data/public/images/indicator.gif +0 -0
- data/public/images/read.gif +0 -0
- data/public/images/search.gif +0 -0
- data/public/images/update.gif +0 -0
- data/public/javascripts/flashobject.js +168 -0
- data/public/javascripts/history.js +48 -0
- data/public/playerProductInstall.swf +0 -0
- data/public/stylesheets/default.css +28 -0
- data/tasks/compile_swf.rake +100 -0
- data/tasks/flex_scaffold.rake +38 -0
- data/uninstall.rb +1 -0
- metadata +125 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
Description:
|
2
|
+
The rest_scaffold_rsource generator acts similar to scaffold_resouce generator and creates a controller that implements
|
3
|
+
the (Flex) REST API. If the model does not exist, it creates it as well.
|
4
|
+
|
5
|
+
It also adds helpers for each model: swf_name and page_title
|
6
|
+
|
7
|
+
From scaffold_resouce:
|
8
|
+
|
9
|
+
The scaffold resource generator creates a model, a controller, and a set of templates that's ready to use as the
|
10
|
+
starting point for your REST-like, resource-oriented application. This basically means that it follows a set of
|
11
|
+
conventions to exploit the full set of HTTP verbs (GET/POST/PUT/DELETE) and is prepared for multi-client access
|
12
|
+
(like one view for HTML, one for an XML API, one for ATOM, etc). Everything comes with sample unit and functional
|
13
|
+
tests as well.
|
14
|
+
|
15
|
+
The generator takes the name of the model as its first argument. This model name is then pluralized to get the
|
16
|
+
controller name. So "scaffold_resource post" will generate a Post model and a PostsController and will be intended
|
17
|
+
for URLs like /posts and /posts/45.
|
18
|
+
|
19
|
+
As additional parameters, the generator will take attribute pairs described by name and type. These attributes will
|
20
|
+
be used to prepopulate the migration to create the table for the model and to give you a set of templates for the
|
21
|
+
view. For example, "scaffold_resource post title:string created_on:date body:text published:boolean" will give
|
22
|
+
you a model with those four attributes, forms to create and edit those models from, and an index that'll list them
|
23
|
+
all.
|
24
|
+
|
25
|
+
You don't have to think up all attributes up front, but it's a good idea of adding just the baseline of what's
|
26
|
+
needed to start really working with the resource.
|
27
|
+
|
28
|
+
Once the generator has run, you'll need to add a declaration to your config/routes.rb file to hook up the rules
|
29
|
+
that'll point URLs to this new resource. If you create a resource like "scaffold_resource post", you'll need to
|
30
|
+
add "map.resources :posts" (notice the plural form) in the routes file. Then your new resource is accessible from
|
31
|
+
/posts.
|
32
|
+
|
33
|
+
Examples:
|
34
|
+
./script/generate scaffold_resource post # no attributes, view will be anemic
|
35
|
+
./script/generate scaffold_resource post title:string created_on:date body:text published:boolean
|
36
|
+
./script/generate scaffold_resource purchase order_id:integer created_at:datetime amount:decimal
|
@@ -0,0 +1,81 @@
|
|
1
|
+
|
2
|
+
class FlexScaffoldResourceGenerator < Rails::Generator::NamedBase
|
3
|
+
attr_reader :controller_name,
|
4
|
+
:controller_class_path,
|
5
|
+
:controller_file_path,
|
6
|
+
:controller_class_nesting,
|
7
|
+
:controller_class_nesting_depth,
|
8
|
+
:controller_class_name,
|
9
|
+
:controller_singular_name,
|
10
|
+
:controller_plural_name
|
11
|
+
alias_method :controller_file_name, :controller_singular_name
|
12
|
+
alias_method :controller_table_name, :controller_plural_name
|
13
|
+
|
14
|
+
def initialize(runtime_args, runtime_options = {})
|
15
|
+
super
|
16
|
+
|
17
|
+
@controller_name = @name.pluralize
|
18
|
+
|
19
|
+
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
|
20
|
+
@controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
|
21
|
+
|
22
|
+
if @controller_class_nesting.empty?
|
23
|
+
@controller_class_name = @controller_class_name_without_nesting
|
24
|
+
else
|
25
|
+
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def manifest
|
30
|
+
record do |m|
|
31
|
+
# Check for class naming collisions.
|
32
|
+
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}ControllerTest", "#{controller_class_name}Helper")
|
33
|
+
m.class_collisions(class_path, "#{class_name}")
|
34
|
+
|
35
|
+
# Controller, helper, and test directories.
|
36
|
+
m.directory File.join('app/controllers', class_path)
|
37
|
+
m.directory File.join('app/helpers', class_path)
|
38
|
+
m.directory File.join('test/functional', class_path)
|
39
|
+
|
40
|
+
m.directory File.join('app/views/layout')
|
41
|
+
m.directory File.join('app/views', "#{plural_name}")
|
42
|
+
|
43
|
+
m.template 'index.rhtml', File.join('app/views', scaffold_name, "index.rhtml")
|
44
|
+
m.template 'layout.rhtml', File.join('app/views/layouts', "#{scaffold_name}.rhtml")
|
45
|
+
|
46
|
+
# Depend on model generator but skip if the model exists.
|
47
|
+
m.template('scaffold_resource:model.rb', File.join('app/models', class_path, "#{file_name}.rb"))
|
48
|
+
|
49
|
+
# Controller class, functional test, and helper class.
|
50
|
+
m.template 'controller.rb',
|
51
|
+
File.join('app/controllers',
|
52
|
+
class_path,
|
53
|
+
"#{controller_plural_name}_controller.rb")
|
54
|
+
|
55
|
+
m.template 'scaffold_resource:functional_test.rb',
|
56
|
+
File.join('test/functional',
|
57
|
+
class_path,
|
58
|
+
"#{file_name}_controller_test.rb")
|
59
|
+
|
60
|
+
m.template 'scaffold_resource:helper.rb',
|
61
|
+
File.join('app/helpers',
|
62
|
+
class_path,
|
63
|
+
"#{controller_plural_name}_helper.rb")
|
64
|
+
|
65
|
+
unless options[:skip_migration]
|
66
|
+
m.migration_template('scaffold_resource:migration.rb', 'db/migrate',
|
67
|
+
:assigns => {:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}",
|
68
|
+
:attributes => attributes},
|
69
|
+
:migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}")
|
70
|
+
end
|
71
|
+
|
72
|
+
m.route_resources controller_file_name
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def scaffold_name
|
78
|
+
FlexScaffold::Config.plugin_name
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
+
|
3
|
+
layout '<%= FlexScaffold::Config.plugin_name %>'
|
4
|
+
flex_scaffold :<%= singular_name %>, :size => '<%= FlexScaffold::Config.default_size %>'
|
5
|
+
|
6
|
+
|
7
|
+
# The following lines can be used instead of the generated definitions
|
8
|
+
# of index, show, new, edit, update, destroy. The generated definitions
|
9
|
+
# are provided as a starting point in case you need to modify them. Otherwise remove.
|
10
|
+
|
11
|
+
# # GET /<%= table_name %>
|
12
|
+
# # GET /<%= table_name %>.xml
|
13
|
+
# # Note: index is has been hijacked for the scaffold to point to flex_index
|
14
|
+
# def index
|
15
|
+
# @<%= table_name %> = <%= class_name %>.find(:all)
|
16
|
+
#
|
17
|
+
# respond_to do |format|
|
18
|
+
# format.html # index.rhtml
|
19
|
+
# format.xml { render :xml => @<%= table_name %>.to_xml }
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# def flex_index
|
24
|
+
# @<%= table_name %> = <%= class_name %>.find(:all)
|
25
|
+
# @swf_name = "_<%= table_name.pluralize %>"
|
26
|
+
# @page_title = "<%= class_name.pluralize %>"
|
27
|
+
#
|
28
|
+
# respond_to do |format|
|
29
|
+
# format.html { render :template => "<%= FlexScaffold::Config.plugin_name %>/index" } # override index.rhtml
|
30
|
+
# format.xml { render :xml => @<%= table_name %>.to_xml }
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# # GET /<%= table_name %>/1
|
35
|
+
# # GET /<%= table_name %>/1.xml
|
36
|
+
# def show
|
37
|
+
# @<%= file_name %> = <%= class_name %>.find(params[:id])
|
38
|
+
#
|
39
|
+
# respond_to do |format|
|
40
|
+
# format.html # show.rhtml
|
41
|
+
# format.xml { render :xml => @<%= file_name %>.to_xml }
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# # GET /<%= table_name %>/new
|
46
|
+
# def new
|
47
|
+
# @<%= file_name %> = <%= class_name %>.new
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# # GET /<%= table_name %>/1;edit
|
51
|
+
# def edit
|
52
|
+
# @<%= file_name %> = <%= class_name %>.find(params[:id])
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# # POST /<%= table_name %>
|
56
|
+
# # POST /<%= table_name %>.xml
|
57
|
+
# def create
|
58
|
+
# @<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
|
59
|
+
#
|
60
|
+
# respond_to do |format|
|
61
|
+
# if @<%= file_name %>.save
|
62
|
+
# flash[:notice] = '<%= class_name %> was successfully created.'
|
63
|
+
# format.html { redirect_to <%= file_name %>_url(@<%= file_name %>) }
|
64
|
+
# format.xml { head :created } #:location => <%= file_name %>_url(@<%= file_name %>)
|
65
|
+
# else
|
66
|
+
# format.html { render :action => "new" }
|
67
|
+
# format.xml { render :xml => @<%= file_name %>.errors.to_xml }
|
68
|
+
# end
|
69
|
+
# end
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# # PUT /<%= table_name %>/1
|
73
|
+
# # PUT /<%= table_name %>/1.xml
|
74
|
+
# def update
|
75
|
+
# @<%= file_name %> = <%= class_name %>.find(params[:id])
|
76
|
+
#
|
77
|
+
# respond_to do |format|
|
78
|
+
# if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
|
79
|
+
# flash[:notice] = '<%= class_name %> was successfully updated.'
|
80
|
+
# format.html { redirect_to <%= file_name %>_url(@<%= file_name %>) }
|
81
|
+
# format.xml { head :ok }
|
82
|
+
# else
|
83
|
+
# format.html { render :action => "edit" }
|
84
|
+
# format.xml { render :xml => @<%= file_name %>.errors.to_xml }
|
85
|
+
# end
|
86
|
+
# end
|
87
|
+
# end
|
88
|
+
#
|
89
|
+
# # DELETE /<%= table_name %>/1
|
90
|
+
# # DELETE /<%= table_name %>/1.xml
|
91
|
+
# def destroy
|
92
|
+
# @<%= file_name %> = <%= class_name %>.find(params[:id])
|
93
|
+
# @<%= file_name %>.destroy
|
94
|
+
#
|
95
|
+
# respond_to do |format|
|
96
|
+
# format.html { redirect_to <%= table_name %>_url }
|
97
|
+
# format.xml { head :ok }
|
98
|
+
# end
|
99
|
+
# end
|
100
|
+
end
|
101
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
7
|
+
<title><%%= @page_title %></title>
|
8
|
+
<%%= flex_scaffold_includes %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
|
12
|
+
<%%= flexobject_version %>
|
13
|
+
|
14
|
+
<%%= yield %>
|
15
|
+
|
16
|
+
<iframe name="_history" src="flex_scaffold/history.htm" frameborder="0" scrolling="no" width="22" height="0"></iframe>
|
17
|
+
|
18
|
+
</body>
|
19
|
+
</html>
|
data/init.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'config'
|
2
|
+
require 'validations'
|
3
|
+
require 'flex_scaffold_plugin'
|
4
|
+
require 'flexobject_view_helper'
|
5
|
+
require 'rest_scaffolding'
|
6
|
+
require 'action_view_helper'
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
# copy all the files over to the main rails app
|
11
|
+
# TODO workout how to invoke the same code as a rake task
|
12
|
+
#Rake::Task['flex:public:install'].invoke
|
13
|
+
|
14
|
+
plugin_dir = File.dirname(__FILE__)
|
15
|
+
public_dir = File.join(RAILS_ROOT, 'public')
|
16
|
+
|
17
|
+
# task :clobber => :environment do
|
18
|
+
FlexScaffold::Config.public_folders.each do |folder|
|
19
|
+
flex_plugin = File.join(RAILS_ROOT, 'public', folder, FlexScaffold::Config.plugin_name)
|
20
|
+
FileUtils.rm_r(Dir.glob(flex_plugin)) unless !File.exist?(flex_plugin)
|
21
|
+
end
|
22
|
+
|
23
|
+
# task :install => :environment do
|
24
|
+
FlexScaffold::Config.public_folders.each do |folder|
|
25
|
+
flex_plugin = File.join(plugin_dir, 'public', folder)
|
26
|
+
dest = File.join(public_dir, folder, FlexScaffold::Config.plugin_name)
|
27
|
+
FileUtils.mkdir(dest) unless File.exist?(dest)
|
28
|
+
FileUtils.cp(Dir.glob(File.join(flex_plugin, '*.*')), dest)
|
29
|
+
end
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
# override render here to ensure that the correct partial is picked up
|
3
|
+
module ActionView #:nodoc:
|
4
|
+
class Base
|
5
|
+
|
6
|
+
|
7
|
+
# Locates the correct template. If the template does not exist at the usual <tt>/views/controller_name</tt>
|
8
|
+
# then it will go and look in <tt>/view/flex_scaffold</tt>
|
9
|
+
#
|
10
|
+
# views/#{controller_class}/#{template}
|
11
|
+
# views/flex_scaffold/#{template}
|
12
|
+
# vendor/plugins/#{flex_scaffold_directory}/themes/#{current_theme}/views/#{template}
|
13
|
+
# vendor/plugins/#{flex_scaffold_directory}/themes/default/views/#{template}
|
14
|
+
#
|
15
|
+
|
16
|
+
# TODO: Fix that it works, currently use generators
|
17
|
+
# Check across multiple paths for files
|
18
|
+
# alias :existing_render_file :render_file
|
19
|
+
# def render_file(template_path, use_full_path = nil, local_assigns = {})
|
20
|
+
# rewrite_path = rewrite_partial_path_for_flex_scaffold template_path
|
21
|
+
# existing_render_file(rewrite_path, use_full_path, local_assigns)
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# def rewrite_partial_path_for_flex_scaffold(partial_path)
|
25
|
+
# path, partial_name = partial_pieces(partial_path)
|
26
|
+
#
|
27
|
+
# # test for the actual file
|
28
|
+
# return partial_path if file_exists? File.join(path, partial_name)
|
29
|
+
#
|
30
|
+
# FlexScaffold::Config.template_search_path.each do |template_path|
|
31
|
+
# return File.join(template_path, partial_name) if file_exists? File.join(template_path, partial_name)
|
32
|
+
# end
|
33
|
+
# return partial_path
|
34
|
+
# end
|
35
|
+
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
module Helpers
|
40
|
+
module AssetTagHelper
|
41
|
+
# produces all the includes in one shot
|
42
|
+
def flex_scaffold_includes
|
43
|
+
js = javascript_include_tag(:defaults, 'flex_scaffold/history')
|
44
|
+
css = stylesheet_link_tag('flex_scaffold/default.css')
|
45
|
+
js + "\n" + css
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/tag_helper'
|
2
|
+
|
3
|
+
module ActionView
|
4
|
+
module Helpers
|
5
|
+
# Provides functionality for working with ActionScript in your views.
|
6
|
+
#
|
7
|
+
module ActionScriptHelper
|
8
|
+
unless const_defined? :ACTIONSCRIPT_PATH
|
9
|
+
ACTIONSCRIPT_PATH = File.join(File.dirname(__FILE__), 'as')
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
# Includes the Action Pack JavaScript libraries inside a single <script>
|
15
|
+
# tag. The function first includes prototype.js and then its core extensions,
|
16
|
+
# (determined by filenames starting with "prototype").
|
17
|
+
# Afterwards, any additional scripts will be included in undefined order.
|
18
|
+
#
|
19
|
+
# Note: The recommended approach is to copy the contents of
|
20
|
+
# lib/action_view/helpers/javascripts/ into your application's
|
21
|
+
# public/javascripts/ directory, and use +javascript_include_tag+ to
|
22
|
+
# create remote <script> links.
|
23
|
+
def define_javascript_functions
|
24
|
+
javascript = '<script type="text/javascript">'
|
25
|
+
|
26
|
+
# load prototype.js and its extensions first
|
27
|
+
prototype_libs = Dir.glob(File.join(JAVASCRIPT_PATH, 'prototype*')).sort.reverse
|
28
|
+
prototype_libs.each do |filename|
|
29
|
+
javascript << "\n" << IO.read(filename)
|
30
|
+
end
|
31
|
+
|
32
|
+
# load other librairies
|
33
|
+
(Dir.glob(File.join(JAVASCRIPT_PATH, '*')) - prototype_libs).each do |filename|
|
34
|
+
javascript << "\n" << IO.read(filename)
|
35
|
+
end
|
36
|
+
javascript << '</script>'
|
37
|
+
end
|
38
|
+
|
39
|
+
# Escape carrier returns and single and double quotes for JavaScript segments.
|
40
|
+
def escape_actionscript(javascript)
|
41
|
+
(javascript || '').gsub('\\','\0\0').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns a JavaScript tag with the +content+ inside. Example:
|
45
|
+
# javascript_tag "alert('All is good')"
|
46
|
+
#
|
47
|
+
# Returns:
|
48
|
+
#
|
49
|
+
# <script type="text/javascript">
|
50
|
+
# //<![CDATA[
|
51
|
+
# alert('All is good')
|
52
|
+
# //]]>
|
53
|
+
# </script>
|
54
|
+
#
|
55
|
+
# +html_options+ may be a hash of attributes for the <script> tag. Example:
|
56
|
+
# javascript_tag "alert('All is good')", :defer => 'true' # => <script defer="true" type="text/javascript">alert('All is good')</script>
|
57
|
+
def actionscript_tag(content, html_options = {})
|
58
|
+
#content_tag("script", javascript_cdata_section(content), html_options.merge(:type => "text/javascript"))
|
59
|
+
end
|
60
|
+
|
61
|
+
def actionscript_cdata_section(content) #:nodoc:
|
62
|
+
"\n//#{cdata_section("\n#{content}\n//")}\n"
|
63
|
+
end
|
64
|
+
|
65
|
+
protected
|
66
|
+
def options_for_actionscript(options)
|
67
|
+
'{' + options.map {|k, v| "#{k}:#{v}"}.sort.join(', ') + '}'
|
68
|
+
end
|
69
|
+
|
70
|
+
def array_or_string_for_actionscript(option)
|
71
|
+
as_option = if option.kind_of?(Array)
|
72
|
+
"['#{option.join('\',\'')}']"
|
73
|
+
elsif !option.nil?
|
74
|
+
"'#{option}'"
|
75
|
+
end
|
76
|
+
as_option
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
data/lib/config.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module FlexScaffold
|
2
|
+
class Config
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def plugin_name
|
7
|
+
"flex_scaffold"
|
8
|
+
end
|
9
|
+
|
10
|
+
def default_size
|
11
|
+
'900x500'
|
12
|
+
end
|
13
|
+
|
14
|
+
def public_folders
|
15
|
+
%w[/ javascripts stylesheets images]
|
16
|
+
end
|
17
|
+
|
18
|
+
def plugin_directory
|
19
|
+
File.expand_path(__FILE__).match(/vendor\/plugins\/(\w*)/)[1]
|
20
|
+
end
|
21
|
+
|
22
|
+
def theme
|
23
|
+
'default'
|
24
|
+
end
|
25
|
+
|
26
|
+
def asset_path(type, filename)
|
27
|
+
File.join(FlexScaffold::Config.plugin_name, FlexScaffold::Config.theme.to_s, filename)
|
28
|
+
end
|
29
|
+
|
30
|
+
def javascripts
|
31
|
+
javascript_dir = File.join(RAILS_ROOT, "vendor", "plugins", FlexScaffold::Config.plugin_directory, "public", "javascripts")
|
32
|
+
Dir.entries(javascript_dir).reject { |e| !e.match(/\.js/) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def template_search_path
|
36
|
+
search_path = []
|
37
|
+
search_path << FlexScaffold::Config.plugin_name
|
38
|
+
search_path << "../../vendor/plugins/#{FlexScaffold::Config.plugin_directory}/themes/#{FlexScaffold::Config.theme.to_s}/views" if FlexScaffold::Config.theme.to_sym != :default
|
39
|
+
search_path << "../../vendor/plugins/#{FlexScaffold::Config.plugin_directory}/themes/default/views"
|
40
|
+
return search_path
|
41
|
+
end
|
42
|
+
|
43
|
+
def available_themes
|
44
|
+
themes_dir = File.join(RAILS_ROOT, "vendor", "plugins", FlexScaffold::Config.plugin_directory, "themes")
|
45
|
+
Dir.entries(themes_dir).reject { |e| e.match(/^\./) } # Get rid of files that start with .
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
module FlexScaffold # :nodoc:
|
3
|
+
|
4
|
+
# extend the class that include this with the methods in ClassMethods
|
5
|
+
def self.included(base)
|
6
|
+
super
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
# Adds a actions to the controller.
|
13
|
+
|
14
|
+
# == Autogeneration ==
|
15
|
+
# Browse through the model
|
16
|
+
# Create the mxml files
|
17
|
+
# Compile to swf
|
18
|
+
# Move to public
|
19
|
+
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
ActionController::Base.send(:include, FlexScaffold)
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# Author:: toddb
|
2
|
+
# Based on: Oliver Steele (2006)
|
3
|
+
# Copyright:: Copyright (c) 2007 toddb. All rights reserved.
|
4
|
+
# License:: MIT License.
|
5
|
+
|
6
|
+
require 'action_view'
|
7
|
+
|
8
|
+
module ActionView #:nodoc:
|
9
|
+
module Helpers # :nodoc:
|
10
|
+
module FlexObjectHelper # :nodoc:
|
11
|
+
def self.included(base)
|
12
|
+
base.class_eval do
|
13
|
+
include InstanceMethods
|
14
|
+
end
|
15
|
+
end
|
16
|
+
module InstanceMethods
|
17
|
+
# Returns a path to a Flash object. The +src+ can be supplied as:
|
18
|
+
#
|
19
|
+
# * a full path, such as "/swfs/flex_scaffold/phones.swf"
|
20
|
+
# * a file name such "phones.swf"
|
21
|
+
# * a file name without an extension, such as "phones"
|
22
|
+
def flexobject_path source
|
23
|
+
compute_public_path source, File.join('swfs', FlexScaffold::Config.plugin_name), 'swf'
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns a set of tags that display a Flash object within an
|
27
|
+
# HTML page.
|
28
|
+
#
|
29
|
+
# Options:
|
30
|
+
# * <tt>:div_id</tt> - the HTML +id+ of the +div+ element that is used to contain the Flash object; default "flashcontent"
|
31
|
+
# * <tt>:flash_id</tt> - the +id+ of the Flash object itself.
|
32
|
+
# * <tt>:background_color</tt> - the background color of the Flash object; default white
|
33
|
+
# * <tt>:flash_version</tt> - the version of the Flash player that is required; default "7.0.0"
|
34
|
+
# * <tt>:size</tt> - the size of the Flash object, in the form "100x100". Defaults to "100%x100%"
|
35
|
+
# * <tt>:variables</tt> - a Hash of initialization variables that are passed to the object; default <tt>{:lzproxied => false}</tt>
|
36
|
+
# * <tt>:parameters</tt> - a Hash of parameters that configure the display of the object; default <tt>{:scale => 'noscale'}</tt>
|
37
|
+
# * <tt>:fallback_html</tt> - HTML text that is displayed when the Flash player is not available.
|
38
|
+
#
|
39
|
+
# The following options are for developers. They default to true in
|
40
|
+
# development mode, and false otherwise.
|
41
|
+
# * <tt>:check_for_javascript_include</tt> - if true, the return value will cause the browser to display a diagnostic message if the FlashObject JavaScript was not included.
|
42
|
+
# * <tt>:verify_file_exists</tt> - if true, the return value will cause the browser to display a diagnostic message if the Flash object does not exist.
|
43
|
+
#
|
44
|
+
# (This method is called flexobject_tags instead of flashobject_tag
|
45
|
+
# because it returns a *sequence* of HTML tags: a +div+, followed by
|
46
|
+
# a +script+.)
|
47
|
+
#
|
48
|
+
# It is also renamed to flex rather than the original flash so that there are not
|
49
|
+
# naming clashes if you use openLaszlo at the same time.
|
50
|
+
def flexobject_tags source, options={}
|
51
|
+
path = flexobject_path source
|
52
|
+
#TODO check why RAILS_ROOT is not absolute
|
53
|
+
#verify_file_exists = options.fetch(:verify_file_exists, ENV['RAILS_ENV'] == 'development')
|
54
|
+
#if verify_file_exists and not File.exists?(File.join(RAILS_ROOT, 'public', path))
|
55
|
+
# return "<div><strong>Warning:</strong> The file <code>#{File.join('public', path)}</code> does not exist. Did you forget to execute <tt>rake flex:compile</tt>?</div>"
|
56
|
+
#end
|
57
|
+
div_id = options[:div_id] || 'flashcontent'
|
58
|
+
flash_id = options[:flash_id] || File.basename(source, '.swf')
|
59
|
+
width, height = (options[:size]||'100%x100%').scan(/^(\d*%?)x(\d*%?)$/).first
|
60
|
+
background_color = options[:background_color] || '#ffffff'
|
61
|
+
flash_version = options[:flash_version] || "7.0.0"
|
62
|
+
variables = options.fetch(:variables, {:lzproxied => false})
|
63
|
+
parameters = options.fetch(:parameters, {:scale => 'noscale'})
|
64
|
+
fallback_html = options[:fallback_html] || %q{<p>Requires the Flash plugin. If the plugin is already installed, click <a href="?detectflash=false">here</a>.</p>}
|
65
|
+
if options.fetch(:check_for_javascript_include, ENV['RAILS_ENV'] == 'development')
|
66
|
+
check_for_javascript ="if (typeof FlashObject == 'undefined') document.getElementById('#{div_id}').innerHTML = '<strong>Warning:</strong> FlashObject is undefined. Did you forget to execute <tt>rake update_javascripts</tt>, or to include <tt><%= javascript_include_tag :defaults %></tt> in your view file?';"
|
67
|
+
end
|
68
|
+
return <<-"EOF"
|
69
|
+
<div id="#{div_id}" style="height:#{height}; width:#{width}">
|
70
|
+
#{fallback_html}
|
71
|
+
</div>
|
72
|
+
<script type="text/javascript">//<![CDATA[
|
73
|
+
#{check_for_javascript}
|
74
|
+
var fo = new FlashObject("#{path}", "#{flash_id}", "#{width}", "#{height}", "#{flash_version}", "#{background_color}");
|
75
|
+
#{parameters.map{|k,v|%Q[fo.addVariable("#{k}", "#{v}");]}.join("\n")}
|
76
|
+
#{variables.map{|k,v|%Q[fo.addVariable("#{k}", "#{v}");]}.join("\n")}
|
77
|
+
fo.write("#{div_id}");
|
78
|
+
//]]>
|
79
|
+
</script>
|
80
|
+
EOF
|
81
|
+
end
|
82
|
+
|
83
|
+
# Returns a set of tags that display a Flash object within an
|
84
|
+
# HTML page. Defaults to v9.0.0
|
85
|
+
#
|
86
|
+
# Options:
|
87
|
+
# * <tt>:major</tt> - default to version 9
|
88
|
+
# * <tt>:minor</tt> - default to 0
|
89
|
+
# * <tt>:revision</tt> - default to 0
|
90
|
+
#
|
91
|
+
# Example output:
|
92
|
+
#
|
93
|
+
# <script language="JavaScript" type="text/javascript">
|
94
|
+
# <!--
|
95
|
+
# // -----------------------------------------------------------------------------
|
96
|
+
# // Globals
|
97
|
+
# // Major version of Flash required
|
98
|
+
# var requiredMajorVersion = 9;
|
99
|
+
# // Minor version of Flash required
|
100
|
+
# var requiredMinorVersion = 0;
|
101
|
+
# // Minor version of Flash required
|
102
|
+
# var requiredRevision = 0;
|
103
|
+
# // -----------------------------------------------------------------------------
|
104
|
+
# // -->
|
105
|
+
# </script>
|
106
|
+
|
107
|
+
def flexobject_version options={}
|
108
|
+
|
109
|
+
major = options[:major] || 9
|
110
|
+
minor = options[:minor] || 0
|
111
|
+
revision = options[:revision] || 0
|
112
|
+
|
113
|
+
return <<-"EOF"
|
114
|
+
<script language="JavaScript" type="text/javascript">//<![CDATA[
|
115
|
+
var requiredMajorVersion = #{major};
|
116
|
+
var requiredMinorVersion = #{minor};
|
117
|
+
var requiredRevision = #{revision};
|
118
|
+
//]]>
|
119
|
+
</script>
|
120
|
+
EOF
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
ActionView::Base.class_eval do
|
129
|
+
include ActionView::Helpers::FlexObjectHelper
|
130
|
+
end
|
131
|
+
|
132
|
+
ActionView::Helpers::AssetTagHelper.register_javascript_include_default 'flex_scaffold/flashobject'
|