right-rails 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.textile +50 -0
  3. data/Rakefile +23 -0
  4. data/generators/right_rails/right_rails_generator.rb +41 -0
  5. data/generators/right_rails/templates/iframed.html.erb +10 -0
  6. data/generators/right_scaffold/right_scaffold_generator.rb +53 -0
  7. data/generators/right_scaffold/templates/controller.rb +99 -0
  8. data/generators/right_scaffold/templates/helper.rb +2 -0
  9. data/generators/right_scaffold/templates/layout.html.erb +18 -0
  10. data/generators/right_scaffold/templates/style.css +54 -0
  11. data/generators/right_scaffold/templates/view__form.html.erb +16 -0
  12. data/generators/right_scaffold/templates/view__item.html.erb +13 -0
  13. data/generators/right_scaffold/templates/view_edit.html.erb +6 -0
  14. data/generators/right_scaffold/templates/view_index.html.erb +9 -0
  15. data/generators/right_scaffold/templates/view_new.html.erb +5 -0
  16. data/generators/right_scaffold/templates/view_show.html.erb +10 -0
  17. data/init.rb +12 -0
  18. data/javascripts/right-autocompleter-src.js +303 -0
  19. data/javascripts/right-autocompleter.js +9 -0
  20. data/javascripts/right-behavior-src.js +240 -0
  21. data/javascripts/right-behavior.js +8 -0
  22. data/javascripts/right-calendar-src.js +855 -0
  23. data/javascripts/right-calendar.js +9 -0
  24. data/javascripts/right-dnd-src.js +555 -0
  25. data/javascripts/right-dnd.js +9 -0
  26. data/javascripts/right-effects-src.js +425 -0
  27. data/javascripts/right-effects.js +6 -0
  28. data/javascripts/right-events-src.js +369 -0
  29. data/javascripts/right-events.js +6 -0
  30. data/javascripts/right-json-src.js +176 -0
  31. data/javascripts/right-json.js +6 -0
  32. data/javascripts/right-lightbox-src.js +597 -0
  33. data/javascripts/right-lightbox.js +9 -0
  34. data/javascripts/right-rails-src.js +269 -0
  35. data/javascripts/right-rails.js +9 -0
  36. data/javascripts/right-rater-src.js +248 -0
  37. data/javascripts/right-rater.js +9 -0
  38. data/javascripts/right-selectable-src.js +507 -0
  39. data/javascripts/right-selectable.js +7 -0
  40. data/javascripts/right-slider-src.js +291 -0
  41. data/javascripts/right-slider.js +7 -0
  42. data/javascripts/right-sortable-src.js +221 -0
  43. data/javascripts/right-sortable.js +9 -0
  44. data/javascripts/right-src.js +4939 -0
  45. data/javascripts/right-tabs-src.js +776 -0
  46. data/javascripts/right-tabs.js +6 -0
  47. data/javascripts/right-tooltips-src.js +130 -0
  48. data/javascripts/right-tooltips.js +9 -0
  49. data/javascripts/right-ui-i18n-de.js +29 -0
  50. data/javascripts/right-ui-i18n-en-us.js +11 -0
  51. data/javascripts/right-ui-i18n-es.js +29 -0
  52. data/javascripts/right-ui-i18n-fr.js +29 -0
  53. data/javascripts/right-ui-i18n-jp.js +33 -0
  54. data/javascripts/right-ui-i18n-ru.js +29 -0
  55. data/javascripts/right-ui-i18n-uk.js +29 -0
  56. data/javascripts/right.js +10 -0
  57. data/lib/right-rails.rb +11 -0
  58. data/lib/right_rails/controller_extensions.rb +85 -0
  59. data/lib/right_rails/helpers/basic.rb +111 -0
  60. data/lib/right_rails/helpers/forms.rb +239 -0
  61. data/lib/right_rails/helpers/misc.rb +164 -0
  62. data/lib/right_rails/helpers/rails.rb +166 -0
  63. data/lib/right_rails/helpers.rb +5 -0
  64. data/lib/right_rails/java_script_generator.rb +313 -0
  65. data/lib/right_rails.rb +6 -0
  66. data/spec/lib/right_rails/controller_extensions_spec.rb +60 -0
  67. data/spec/lib/right_rails/helpers/basic_spec.rb +74 -0
  68. data/spec/lib/right_rails/helpers/forms_spec.rb +51 -0
  69. data/spec/lib/right_rails/helpers/misc_spec.rb +120 -0
  70. data/spec/lib/right_rails/helpers/rails_spec.rb +149 -0
  71. data/spec/lib/right_rails/java_script_generator_spec.rb +317 -0
  72. data/spec/spec.opts +5 -0
  73. data/spec/spec_helper.rb +15 -0
  74. metadata +128 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Nikolay V. Nemshilov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,50 @@
1
+ h1. Welcome To RightRails
2
+
3
+ RightRails is a RubyOnRails plugin for RightJS javascript framework.
4
+
5
+ It works as a drop in replacement for all the Prototype/Scriptaculous
6
+ methods, plus it brings some more sweets and routine ajax operations
7
+ organization.
8
+
9
+
10
+ h2. Features
11
+
12
+ * Lightning fast RightJS library
13
+ * Transparent Prototype/Scriptaculous helpers replacement
14
+ * More powerful and flexible new JavaScript generator for RJS
15
+ * Conventional JavaScript interface for the most common AJAX operations
16
+ * Better controller level access to the rjs generator
17
+ * New ajax-friendly scaffold generator
18
+ * Remote files uploading organization
19
+ * Automatic RightJS modules inclusion handling (including i18n modules)
20
+ * Additional FormBuilder methods for calendar and autocomplete fields
21
+ * Underscored and ruby-like aliases for RightJS core methods
22
+
23
+
24
+ h2. Documentation
25
+
26
+ See the wiki-pages for the documentation
27
+
28
+ <a href="http://wiki.github.com/MadRabbit/right-rails">http://wiki.github.com/MadRabbit/right-rails</a>
29
+
30
+
31
+ h3. Usage
32
+
33
+ Install the plugin to your rails application
34
+
35
+ @script/plugin install git://github.com/MadRabbit/right-rails.git@
36
+
37
+ After that run the @right_rails@ generator, which will put all the JavaScripts in place
38
+
39
+ @script/generate right_rails@
40
+
41
+ You also will have an ajax-friendly scaffold generator
42
+
43
+ @script/generate right_scaffold Zing@
44
+
45
+
46
+ The rubygem is still coming soon.
47
+
48
+
49
+
50
+ Copyright (c) 2009 Nikolay V. Nemshilov, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the right_rails plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the right_rails plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'RightRails'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
@@ -0,0 +1,41 @@
1
+ #
2
+ # Copies all the javascripts in place and updates them if necessary
3
+ #
4
+
5
+ class RightRailsGenerator < Rails::Generator::Base
6
+
7
+ mandatory_options :source => "#{File.dirname(__FILE__)}/../../javascripts"
8
+
9
+ def manifest
10
+ record do |m|
11
+ # creating the javascript directories
12
+ m.directory 'public/javascripts/right'
13
+ m.directory 'public/javascripts/right/i18n'
14
+
15
+ # copying the javascript files
16
+ Dir.open(options[:source]).each do |file|
17
+ unless ['.', '..'].include?(file)
18
+ destination = if ['right.js', 'right-src.js'].include?(file)
19
+ file
20
+ elsif file.include?('ui-i18n')
21
+ file.gsub('right-', 'right/').gsub('ui-i18n-', 'i18n/')
22
+ else
23
+ file.gsub('right-', 'right/')
24
+ end
25
+
26
+ m.file file, "public/javascripts/#{destination}", :chmod => 0644
27
+ end
28
+ end
29
+
30
+ # creating the iframed uploads layout
31
+ m.directory "app/views/layouts"
32
+ m.file "/../generators/right_rails/templates/iframed.html.erb", "app/views/layouts/iframed.html.erb"
33
+ end
34
+ end
35
+
36
+
37
+ def banner
38
+ "Usage: #{$0} right_rails"
39
+ end
40
+
41
+ end
@@ -0,0 +1,10 @@
1
+ <!-- iframed uploads JS responses layout -->
2
+ <html>
3
+ <head>
4
+ <script type="text/javascript">
5
+ with (window.parent) {
6
+ <%= yield %>
7
+ }
8
+ </script>
9
+ </head>
10
+ </html>
@@ -0,0 +1,53 @@
1
+ #
2
+ # This is pretty much the same thing as the native rails scaffold generator
3
+ # only without tests, plust it adds the '.js' format responses and fixes
4
+ # the templates organization
5
+ #
6
+ #
7
+ class RightScaffoldGenerator < ScaffoldGenerator
8
+ def manifest
9
+ record do |m|
10
+ # Check for class naming collisions.
11
+ m.class_collisions("#{controller_class_name}Controller", "#{controller_class_name}Helper")
12
+ m.class_collisions(class_name)
13
+
14
+ # Controller, helper, views, test and stylesheets directories.
15
+ m.directory(File.join('app/models', class_path))
16
+ m.directory(File.join('app/controllers', controller_class_path))
17
+ m.directory(File.join('app/helpers', controller_class_path))
18
+ m.directory(File.join('app/views', controller_class_path, controller_file_name))
19
+ m.directory(File.join('app/views/layouts', controller_class_path))
20
+ m.directory(File.join('public/stylesheets', class_path))
21
+
22
+ for action in scaffold_views
23
+ m.template(
24
+ "view_#{action}.html.erb",
25
+ File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.erb")
26
+ )
27
+ end
28
+
29
+ m.template "view__form.html.erb", File.join('app/views', controller_class_path, controller_file_name, "_form.html.erb")
30
+ m.template "view__item.html.erb", File.join('app/views', controller_class_path, controller_file_name, "_#{file_name}.html.erb")
31
+
32
+ # Layout and stylesheet.
33
+ m.template('layout.html.erb', File.join('app/views/layouts', controller_class_path, "#{controller_file_name}.html.erb"))
34
+ m.template('style.css', 'public/stylesheets/scaffold.css')
35
+
36
+ m.template(
37
+ 'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
38
+ )
39
+
40
+ m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
41
+
42
+ m.route_resources controller_file_name
43
+
44
+ m.dependency 'model', [name] + @args, :collision => :skip
45
+ end
46
+ end
47
+
48
+ protected
49
+
50
+ def banner
51
+ "Usage: #{$0} right_scaffold ModelName [field:type, field:type]"
52
+ end
53
+ end
@@ -0,0 +1,99 @@
1
+ class <%= controller_class_name %>Controller < ApplicationController
2
+ # GET /<%= table_name %>
3
+ # GET /<%= table_name %>.xml
4
+ def index
5
+ @<%= table_name %> = <%= class_name %>.all
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.xml { render :xml => @<%= table_name %> }
10
+ end
11
+ end
12
+
13
+ # GET /<%= table_name %>/1
14
+ # GET /<%= table_name %>/1.xml
15
+ def show
16
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.xml { render :xml => @<%= file_name %> }
21
+ end
22
+ end
23
+
24
+ # GET /<%= table_name %>/new
25
+ # GET /<%= table_name %>/new.xml
26
+ def new
27
+ @<%= file_name %> = <%= class_name %>.new
28
+
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.xml { render :xml => @<%= file_name %> }
32
+ end
33
+ end
34
+
35
+ # GET /<%= table_name %>/1/edit
36
+ # GET /<%= table_name %>/1/edit.js
37
+ def edit
38
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
39
+
40
+ respond_to do |format|
41
+ format.js { render rjs.show_form_for(@<%= file_name %>) }
42
+ format.any # edit.html.erb
43
+ end
44
+ end
45
+
46
+ # POST /<%= table_name %>
47
+ # POST /<%= table_name %>.xml
48
+ # POST /<%= table_name %>.js
49
+ def create
50
+ @<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
51
+
52
+ respond_to do |format|
53
+ if @<%= file_name %>.save
54
+ flash[:notice] = '<%= class_name %> was successfully created.'
55
+ format.html { redirect_to(@<%= file_name %>) }
56
+ format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
57
+ format.js { render rjs.insert_and_care(@<%= file_name %>) }
58
+ else
59
+ format.html { render :action => "new" }
60
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
61
+ format.js { render rjs.replace_form_for(@<%= file_name %>) }
62
+ end
63
+ end
64
+ end
65
+
66
+ # PUT /<%= table_name %>/1
67
+ # PUT /<%= table_name %>/1.xml
68
+ # PUT /<%= table_name %>/1.js
69
+ def update
70
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
71
+
72
+ respond_to do |format|
73
+ if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
74
+ flash[:notice] = '<%= class_name %> was successfully updated.'
75
+ format.html { redirect_to(@<%= file_name %>) }
76
+ format.xml { head :ok }
77
+ format.js { render rjs.replace_and_care(@<%= file_name %>) }
78
+ else
79
+ format.html { render :action => "edit" }
80
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
81
+ format.js { render rjs.replace_form_for(@<%= file_name %>) }
82
+ end
83
+ end
84
+ end
85
+
86
+ # DELETE /<%= table_name %>/1
87
+ # DELETE /<%= table_name %>/1.xml
88
+ # DELETE /<%= table_name %>/1.js
89
+ def destroy
90
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
91
+ @<%= file_name %>.destroy
92
+
93
+ respond_to do |format|
94
+ format.html { redirect_to(<%= table_name %>_url) }
95
+ format.xml { head :ok }
96
+ format.js { render rjs.remove(@<%= file_name %>) }
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,2 @@
1
+ module <%= controller_class_name %>Helper
2
+ end
@@ -0,0 +1,18 @@
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><%= controller_class_name %>: <%%= controller.action_name %></title>
8
+ <%%= stylesheet_link_tag 'scaffold' %>
9
+ <%%= rightjs_scripts %>
10
+ </head>
11
+ <body>
12
+
13
+ <%%= flashes %>
14
+
15
+ <%%= yield %>
16
+
17
+ </body>
18
+ </html>
@@ -0,0 +1,54 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ .fieldWithErrors {
20
+ padding: 2px;
21
+ background-color: red;
22
+ display: table;
23
+ }
24
+
25
+ #errorExplanation {
26
+ width: 400px;
27
+ border: 2px solid red;
28
+ padding: 7px;
29
+ padding-bottom: 12px;
30
+ margin-bottom: 20px;
31
+ background-color: #f0f0f0;
32
+ }
33
+
34
+ #errorExplanation h2 {
35
+ text-align: left;
36
+ font-weight: bold;
37
+ padding: 5px 5px 5px 15px;
38
+ font-size: 12px;
39
+ margin: -7px;
40
+ background-color: #c00;
41
+ color: #fff;
42
+ }
43
+
44
+ #errorExplanation p {
45
+ color: #333;
46
+ margin-bottom: 0;
47
+ padding: 5px;
48
+ }
49
+
50
+ #errorExplanation ul li {
51
+ font-size: 12px;
52
+ list-style: square;
53
+ }
54
+
@@ -0,0 +1,16 @@
1
+ <%% form_for(@<%= singular_name %>) do |f| %>
2
+ <%%= f.error_messages %>
3
+
4
+ <% for attribute in attributes -%>
5
+ <p>
6
+ <%%= f.label :<%= attribute.name %> %><br />
7
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
8
+ </p>
9
+ <% end -%>
10
+
11
+ <p class="buttons">
12
+ <%%= f.submit f.object.new_record? ? 'Create' : 'Update' %>
13
+ <%%= link_to_function 'Cancel', "$(this).parent('form').remove();" if request.xhr? %>
14
+ <%%= image_tag 'spinner.gif', :style => 'display:none', :class => :spinner %>
15
+ </p>
16
+ <%% end %>
@@ -0,0 +1,13 @@
1
+ <%% div_for <%= singular_name %> do %>
2
+ <% for attribute in attributes -%>
3
+ <p>
4
+ <label><%= attribute.name %></label>: <%%=h <%= singular_name %>.<%= attribute.name %> %>
5
+ </p>
6
+ <% end -%>
7
+
8
+ <div class="actions">
9
+ <%%= link_to 'Show', <%= singular_name %> %> |
10
+ <%%= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>), :class => :edit %> |
11
+ <%%= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete, :class => :destroy %>
12
+ </div>
13
+ <%% end -%>
@@ -0,0 +1,6 @@
1
+ <h1>Editing <%= singular_name %></h1>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <%%= link_to 'Show', @<%= singular_name %> %> |
6
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -0,0 +1,9 @@
1
+ <h1>Listing <%= plural_name %></h1>
2
+
3
+ <div id="<%= plural_name %>">
4
+ <%%= render @<%= plural_name %> %>
5
+ </div>
6
+
7
+ <br />
8
+
9
+ <%%= link_to 'New <%= singular_name %>', new_<%= singular_name %>_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New <%= singular_name %></h1>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -0,0 +1,10 @@
1
+ <% for attribute in attributes -%>
2
+ <p>
3
+ <b><%= attribute.column.human_name %>:</b>
4
+ <%%=h @<%= singular_name %>.<%= attribute.name %> %>
5
+ </p>
6
+
7
+ <% end -%>
8
+
9
+ <%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
10
+ <%%= link_to 'Back', <%= plural_name %>_path %>
data/init.rb ADDED
@@ -0,0 +1,12 @@
1
+ # Include hook code here
2
+
3
+ if defined?(ActionController)
4
+ class ActionController::Base
5
+ include RightRails::ControllerExtensions
6
+
7
+ helper RightRails::Helpers::Basic,
8
+ RightRails::Helpers::Rails,
9
+ RightRails::Helpers::Forms,
10
+ RightRails::Helpers::Misc
11
+ end
12
+ end