right-rails 0.6.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/CHANGELOG +8 -0
  2. data/README.rdoc +71 -0
  3. data/Rakefile +144 -14
  4. data/generators/right_rails/right_rails_generator.rb +18 -21
  5. data/init.rb +11 -32
  6. data/lib/generators/right_rails/right_rails_generator.rb +27 -0
  7. data/lib/generators/right_rails/templates/iframed.html.erb +10 -0
  8. data/lib/right-rails.rb +1 -1
  9. data/lib/right_rails/config.rb +278 -0
  10. data/lib/right_rails/controller_extensions.rb +10 -5
  11. data/lib/right_rails/helpers/basic.rb +10 -66
  12. data/lib/right_rails/helpers/forms.rb +141 -139
  13. data/lib/right_rails/helpers/misc.rb +45 -67
  14. data/lib/right_rails/helpers/rails.rb +40 -105
  15. data/lib/right_rails/helpers.rb +364 -1
  16. data/lib/right_rails/java_script_generator.rb +34 -24
  17. data/lib/right_rails.rb +6 -1
  18. data/{images → public/images}/colorpicker.png +0 -0
  19. data/{images → public/images}/resizable.png +0 -0
  20. data/public/javascripts/right/autocompleter-src.js +612 -0
  21. data/public/javascripts/right/autocompleter.js +18 -0
  22. data/public/javascripts/right/calendar-src.js +1448 -0
  23. data/public/javascripts/right/calendar.js +36 -0
  24. data/public/javascripts/right/colorpicker-src.js +967 -0
  25. data/public/javascripts/right/colorpicker.js +26 -0
  26. data/{javascripts/right-dnd-src.js → public/javascripts/right/dnd-src.js} +86 -52
  27. data/public/javascripts/right/dnd.js +20 -0
  28. data/{javascripts/right-effects-src.js → public/javascripts/right/effects-src.js} +90 -45
  29. data/public/javascripts/right/effects.js +17 -0
  30. data/{javascripts/right-ui-i18n-de.js → public/javascripts/right/i18n/de.js} +7 -7
  31. data/{javascripts/right-ui-i18n-en-us.js → public/javascripts/right/i18n/en-us.js} +1 -1
  32. data/{javascripts/right-ui-i18n-es.js → public/javascripts/right/i18n/es.js} +7 -7
  33. data/{javascripts/right-ui-i18n-fr.js → public/javascripts/right/i18n/fr.js} +7 -7
  34. data/{javascripts/right-ui-i18n-hu.js → public/javascripts/right/i18n/hu.js} +7 -7
  35. data/{javascripts/right-ui-i18n-jp.js → public/javascripts/right/i18n/jp.js} +7 -7
  36. data/{javascripts/right-ui-i18n-nl.js → public/javascripts/right/i18n/nl.js} +7 -7
  37. data/{javascripts/right-ui-i18n-pt-br.js → public/javascripts/right/i18n/pt-br.js} +7 -7
  38. data/{javascripts/right-ui-i18n-ru.js → public/javascripts/right/i18n/ru.js} +7 -7
  39. data/{javascripts/right-ui-i18n-ua.js → public/javascripts/right/i18n/ua.js} +17 -12
  40. data/public/javascripts/right/in-edit-src.js +352 -0
  41. data/public/javascripts/right/in-edit.js +13 -0
  42. data/public/javascripts/right/json-src.js +160 -0
  43. data/public/javascripts/right/json.js +10 -0
  44. data/public/javascripts/right/lightbox-src.js +881 -0
  45. data/public/javascripts/right/lightbox.js +24 -0
  46. data/{javascripts/right-rails-src.js → public/javascripts/right/rails-src.js} +195 -171
  47. data/public/javascripts/right/rails.js +14 -0
  48. data/public/javascripts/right/rater-src.js +366 -0
  49. data/public/javascripts/right/rater.js +13 -0
  50. data/public/javascripts/right/resizable-src.js +420 -0
  51. data/public/javascripts/right/resizable.js +15 -0
  52. data/public/javascripts/right/selectable-src.js +687 -0
  53. data/public/javascripts/right/selectable.js +22 -0
  54. data/public/javascripts/right/slider-src.js +377 -0
  55. data/public/javascripts/right/slider.js +14 -0
  56. data/public/javascripts/right/sortable-src.js +392 -0
  57. data/public/javascripts/right/sortable.js +16 -0
  58. data/public/javascripts/right/tabs-src.js +1123 -0
  59. data/public/javascripts/right/tabs.js +29 -0
  60. data/public/javascripts/right/tooltip-src.js +307 -0
  61. data/public/javascripts/right/tooltip.js +12 -0
  62. data/public/javascripts/right/uploader-src.js +283 -0
  63. data/public/javascripts/right/uploader.js +13 -0
  64. data/{javascripts → public/javascripts}/right-olds-src.js +134 -186
  65. data/public/javascripts/right-olds.js +18 -0
  66. data/public/javascripts/right-safe-src.js +161 -0
  67. data/public/javascripts/right-safe.js +8 -0
  68. data/{javascripts → public/javascripts}/right-src.js +2558 -1750
  69. data/public/javascripts/right.js +92 -0
  70. data/spec/lib/right_rails/config_spec.rb +133 -0
  71. data/spec/lib/right_rails/controller_extensions_spec.rb +1 -1
  72. data/spec/lib/right_rails/helpers/basic_spec.rb +77 -66
  73. data/spec/lib/right_rails/helpers/forms_spec.rb +231 -33
  74. data/spec/lib/right_rails/helpers/misc_spec.rb +94 -26
  75. data/spec/lib/right_rails/helpers/rails_spec.rb +42 -7
  76. data/spec/lib/right_rails/helpers_spec.rb +125 -0
  77. data/spec/lib/right_rails/java_script_generator_spec.rb +30 -0
  78. data/spec/rcov.opts +3 -0
  79. data/spec/spec_helper.rb +12 -7
  80. metadata +70 -61
  81. data/README.textile +0 -69
  82. data/javascripts/right-autocompleter-src.js +0 -318
  83. data/javascripts/right-autocompleter.js +0 -9
  84. data/javascripts/right-behavior-src.js +0 -261
  85. data/javascripts/right-behavior.js +0 -8
  86. data/javascripts/right-calendar-src.js +0 -946
  87. data/javascripts/right-calendar.js +0 -9
  88. data/javascripts/right-colorpicker-src.js +0 -635
  89. data/javascripts/right-colorpicker.js +0 -9
  90. data/javascripts/right-dnd.js +0 -9
  91. data/javascripts/right-effects.js +0 -6
  92. data/javascripts/right-events-src.js +0 -321
  93. data/javascripts/right-events.js +0 -6
  94. data/javascripts/right-in-edit-src.js +0 -194
  95. data/javascripts/right-in-edit.js +0 -6
  96. data/javascripts/right-json-src.js +0 -141
  97. data/javascripts/right-json.js +0 -6
  98. data/javascripts/right-lightbox-src.js +0 -651
  99. data/javascripts/right-lightbox.js +0 -9
  100. data/javascripts/right-olds.js +0 -9
  101. data/javascripts/right-rails.js +0 -9
  102. data/javascripts/right-rater-src.js +0 -253
  103. data/javascripts/right-rater.js +0 -9
  104. data/javascripts/right-resizable-src.js +0 -336
  105. data/javascripts/right-resizable.js +0 -9
  106. data/javascripts/right-selectable-src.js +0 -565
  107. data/javascripts/right-selectable.js +0 -7
  108. data/javascripts/right-slider-src.js +0 -288
  109. data/javascripts/right-slider.js +0 -7
  110. data/javascripts/right-sortable-src.js +0 -225
  111. data/javascripts/right-sortable.js +0 -9
  112. data/javascripts/right-tabs-src.js +0 -937
  113. data/javascripts/right-tabs.js +0 -6
  114. data/javascripts/right-tooltips-src.js +0 -195
  115. data/javascripts/right-tooltips.js +0 -9
  116. data/javascripts/right-uploader-src.js +0 -167
  117. data/javascripts/right-uploader.js +0 -9
  118. data/javascripts/right.js +0 -7
@@ -0,0 +1,278 @@
1
+ #
2
+ # = RightRails configuration interface
3
+ #
4
+ # You can adjust the following settings with the RightRails::Config object
5
+ #
6
+ # - RightRails::Config.env _auto_, _production_ or _development_
7
+ # - RightRails::Config.public_path _auto_ or some string
8
+ # - RightRails::Config.locales_path _auto_ or some string
9
+ # - RightRails::Config.safe_mode _auto_, +true+ or +false+
10
+ # - RightRails::Config.rightjs_version _auto_, 2 or 1
11
+ # - RightRails::Config.include_rails_module +true+ or +false+
12
+ # - RightRails::Config.swap_builds_and_sources +true+ or +false+
13
+ # - RightRails::Config.include_scripts_automatically +true+ or +false+
14
+ #
15
+ # When you set a property in _auto_ then the script will try to figure the
16
+ # parameters out by the current environment and the content of the
17
+ # public/javascript/right.js file
18
+ #
19
+ module RightRails::Config
20
+
21
+ DEFAULT_PUBLIC_PATH = 'auto' # 'auto' or some path
22
+ DEFAULT_SAFE_MODE = 'auto' # 'auto', true or false
23
+ DEFAULT_RIGHTJS_VERSION = 'auto' # 'auto', 2 or 1
24
+ DEFAULT_ENVIRONMENT = 'auto' # 'auto', 'production' or 'development'
25
+ DEFAULT_RIGHTJS_LOCATION = 'javascripts/right.js'
26
+ DEFAULT_LOCALES_LOCATION = 'javascripts/right/i18n'
27
+ DEFAULT_INCLUDE_RAILS = true # true or false
28
+ DEFAULT_AUTO_INCLUDES = true # true or false
29
+ DEFAULT_SWAP_BUILDS = true # true or false
30
+
31
+ class << self
32
+ #
33
+ # Resetting the configuration to the defaults
34
+ #
35
+ def reset!
36
+ remove_instance_variable(:@environment) if defined?(@environment)
37
+ remove_instance_variable(:@public_path) if defined?(@public_path)
38
+ remove_instance_variable(:@locales_path) if defined?(@locales_path)
39
+ remove_instance_variable(:@safe_mode) if defined?(@safe_mode)
40
+ remove_instance_variable(:@rightjs_version) if defined?(@rightjs_version)
41
+ remove_instance_variable(:@include_rails) if defined?(@include_rails)
42
+ remove_instance_variable(:@auto_includes) if defined?(@auto_includes)
43
+ remove_instance_variable(:@swap_builds) if defined?(@swap_builds)
44
+ end
45
+
46
+ #
47
+ # Returns the currently used environment
48
+ #
49
+ # By default will use the Rails.env
50
+ #
51
+ def env
52
+ unless defined?(@environment)
53
+ self.env = DEFAULT_ENVIRONMENT
54
+ end
55
+
56
+ @environment
57
+ end
58
+
59
+ #
60
+ # Sets the current environment, which will effectively make
61
+ # RightRails to switch between the builds and src versions of
62
+ # right.js and modules
63
+ #
64
+ # You can use 'production', 'development' or 'auto'
65
+ #
66
+ def env=(value)
67
+ if value == 'auto'
68
+ value = if in_rails?
69
+ Rails.env
70
+ else
71
+ "production"
72
+ end
73
+ end
74
+
75
+ @environment = value.to_s == 'production' ? 'production' : 'development'
76
+ end
77
+
78
+ #
79
+ # Returns a marker if we are in the _development_ environment
80
+ #
81
+ def dev_env?
82
+ env == 'development'
83
+ end
84
+
85
+ #
86
+ # Returns the public_html directory path
87
+ #
88
+ # By default it will return the Rails.public_path
89
+ #
90
+ def public_path
91
+ unless defined?(@public_path)
92
+ self.public_path = DEFAULT_PUBLIC_PATH
93
+ end
94
+
95
+ @public_path
96
+ end
97
+
98
+ #
99
+ # If you have your public_html somewhere else
100
+ # this is the place where you can define it
101
+ #
102
+ def public_path=(path)
103
+ if path == 'auto'
104
+ path = self.public_path = if in_rails?
105
+ Rails.public_path
106
+ else
107
+ # TODO other frameworks handling in here
108
+ "public"
109
+ end
110
+ end
111
+
112
+ # getting rid of the trailing slash
113
+ if path.slice(path.size-1, path.size) == '/'
114
+ path = path.slice(0, path.size-1)
115
+ end
116
+
117
+ @public_path = path.dup
118
+ end
119
+
120
+ #
121
+ # Returns a full-path to the localization modules directory
122
+ #
123
+ def locales_path
124
+ unless defined?(@locales_path)
125
+ self.locales_path = "#{public_path}/#{DEFAULT_LOCALES_LOCATION}"
126
+ end
127
+
128
+ @locales_path
129
+ end
130
+
131
+ #
132
+ # Sets the RightJS localilzation modules directory path
133
+ #
134
+ def locales_path=(path)
135
+ # getting rid of the trailing slash
136
+ if path.slice(path.size-1, path.size) == '/'
137
+ path = path.slice(0, path.size-1)
138
+ end
139
+
140
+ @locales_path = path
141
+ end
142
+
143
+ #
144
+ # Checks if the RightJS is used in the safe-mode
145
+ #
146
+ def safe_mode
147
+ unless defined?(@safe_mode)
148
+ self.safe_mode = DEFAULT_SAFE_MODE
149
+ end
150
+
151
+ @safe_mode
152
+ end
153
+
154
+ #
155
+ # Setup whether RightJS is used in the safe-mode or not
156
+ #
157
+ # You can use boolean values or a string 'auto' (default)
158
+ # in which case it will try to figure it out by reading the
159
+ # `public/javascripts/right.js` file
160
+ #
161
+ def safe_mode=(value)
162
+ @safe_mode = !!(value == 'auto' ? read_rightjs_file =~ /\.safe\s*=\s*true/ : value)
163
+ end
164
+
165
+ #
166
+ # Returns the RightJS version (2 or 1)
167
+ #
168
+ def rightjs_version
169
+ unless defined?(@rightjs_version)
170
+ self.rightjs_version = DEFAULT_RIGHTJS_VERSION
171
+ end
172
+
173
+ @rightjs_version
174
+ end
175
+
176
+ #
177
+ # With this method you can set up which version of RightJS do you use
178
+ # 2 or 1. You also can set it to a string 'auto' (by default) in which
179
+ # case it will try to figure it out by reading the `public/javascripts/right.js`
180
+ # file
181
+ #
182
+ def rightjs_version=(value)
183
+ if value == 'auto'
184
+ value = read_rightjs_file =~ /version\s*(:|=)\s*("|')1/ ? 1 : 2
185
+ end
186
+
187
+ @rightjs_version = value < 2 ? 1 : 2
188
+ end
189
+
190
+ #
191
+ # Returns a marker if the script should automatically include
192
+ # the ruby-on-rails module for RightJS
193
+ #
194
+ def include_rails_module
195
+ unless defined?(@include_rails)
196
+ self.include_rails_module = DEFAULT_INCLUDE_RAILS
197
+ end
198
+
199
+ @include_rails
200
+ end
201
+
202
+ #
203
+ # Sets the marker if the plugin should automatically include
204
+ # the ruby-on-rails module for RightJS
205
+ #
206
+ def include_rails_module=(value)
207
+ @include_rails = !! value
208
+ end
209
+
210
+ #
211
+ # Checks if the plugin should automatically swap between
212
+ # the builds and the source-versions of JavaScript files
213
+ # depending on current environment
214
+ #
215
+ def swap_builds_and_sources
216
+ unless defined?(@swap_builds)
217
+ self.swap_builds_and_sources = DEFAULT_SWAP_BUILDS
218
+ end
219
+
220
+ @swap_builds
221
+ end
222
+
223
+ #
224
+ # Sets the marker if the plugin should automatically
225
+ # swap between source and builds of JavaScript files
226
+ #
227
+ def swap_builds_and_sources=(value)
228
+ @swap_builds = !! value
229
+ end
230
+
231
+ #
232
+ # Checks if the plugin should include JavaScript modules
233
+ # automatically when they needed
234
+ #
235
+ def include_scripts_automatically
236
+ unless defined?(@auto_includes)
237
+ self.include_scripts_automatically = DEFAULT_AUTO_INCLUDES
238
+ end
239
+
240
+ @auto_includes
241
+ end
242
+
243
+ #
244
+ # Sets the marker if the plugin should automatically include
245
+ # all the JavaScript files on the page when they needed
246
+ #
247
+ def include_scripts_automatically=(value)
248
+ @auto_includes = !! value
249
+ end
250
+
251
+ # boolean methods aliases
252
+ alias_method :safe_mode?, :safe_mode
253
+ alias_method :include_rails_module? , :include_rails_module
254
+ alias_method :swap_builds_and_sources? , :swap_builds_and_sources
255
+ alias_method :include_scripts_automatically?, :include_scripts_automatically
256
+
257
+ private
258
+
259
+ #
260
+ # reading the `public/javascripts/right.js` file for the purposes
261
+ # of the automatic configuration
262
+ #
263
+ # NOTE: _will_not_ raise any errors if the file is not found
264
+ #
265
+ def read_rightjs_file
266
+ File.read("#{public_path}/#{DEFAULT_RIGHTJS_LOCATION}")
267
+ rescue
268
+ ''
269
+ end
270
+
271
+ #
272
+ # Checking if we are in the Ruby-on-Rails environment
273
+ #
274
+ def in_rails?
275
+ !Object.const_get(:Rails).nil?
276
+ end
277
+ end
278
+ end
@@ -30,9 +30,14 @@ module RightRails::ControllerExtensions
30
30
  # end
31
31
  #
32
32
  def rjs(options={}, &block)
33
- @template.send(:_evaluate_assigns_and_ivars)
33
+ template = if @template
34
+ @template.send(:_evaluate_assigns_and_ivars)
35
+ @template
36
+ else
37
+ view_context
38
+ end
34
39
 
35
- wrapper = RenderWrapper.new(@template, options)
40
+ wrapper = RenderWrapper.new(template, options)
36
41
 
37
42
  if block_given?
38
43
  wrapper.render_block(&block)
@@ -41,6 +46,8 @@ module RightRails::ControllerExtensions
41
46
  end
42
47
  end
43
48
 
49
+ private
50
+
44
51
  #
45
52
  # This class wraps the standard JavaScript responses in the controller
46
53
  #
@@ -65,8 +72,6 @@ module RightRails::ControllerExtensions
65
72
  render
66
73
  end
67
74
 
68
- protected
69
-
70
75
  #
71
76
  # Compiles the options for the controller#render method
72
77
  #
@@ -75,7 +80,7 @@ module RightRails::ControllerExtensions
75
80
 
76
81
  # iframed uploads context overloading
77
82
  if @template.request.content_type == 'multipart/form-data'
78
- result.merge! :content_type => Mime::HTML, :layout => 'iframed'
83
+ result.merge! :content_type => Mime::HTML, :layout => 'iframed.html.erb'
79
84
  end
80
85
 
81
86
  result.merge! @options
@@ -9,29 +9,17 @@ module RightRails::Helpers::Basic
9
9
  # USAGE:
10
10
  # <%= rightjs_scripts %>
11
11
  #
12
- # you can also predefine the list of modules to load
12
+ # you can also predefine the list of modules to load
13
13
  #
14
14
  # <%= rightjs_scripts 'lightbox', 'calendar' %>
15
15
  #
16
16
  def rightjs_scripts(*modules)
17
- scripts = ['right']
17
+ options = modules.last.is_a?(Hash) ? modules.pop : nil
18
18
 
19
- # including the submodules
20
- rightjs_include_module *modules
21
- ((@_right_scripts || []) + ['rails']).each do |package|
22
- scripts << "right/#{package}"
23
- end
19
+ rightjs_require_module *modules
24
20
 
25
- # use the sources in the development environment
26
- if defined?(RAILS_ENV) && RAILS_ENV == 'development'
27
- scripts.collect!{ |name| name + '-src' }
28
- end
29
-
30
- # include the localization script if available
31
- if defined?(I18n) && defined?(Rails.root)
32
- locale_file = "right/i18n/#{I18n.locale.to_s.downcase}"
33
- scripts << locale_file if File.exists? "#{Rails.root}/public/javascripts/#{locale_file}.js"
34
- end
21
+ scripts = RightRails::Helpers.required_js_files(self)
22
+ scripts << options unless options.nil?
35
23
 
36
24
  javascript_include_tag *scripts
37
25
  end
@@ -61,9 +49,7 @@ module RightRails::Helpers::Basic
61
49
  # end %>
62
50
  #
63
51
  def rjs_tag(&block)
64
- javascript_tag do
65
- rjs(&block)
66
- end
52
+ javascript_tag rjs(&block).to_s
67
53
  end
68
54
 
69
55
  #
@@ -71,56 +57,14 @@ module RightRails::Helpers::Basic
71
57
  # so that the #link_to_function method was working properly
72
58
  #
73
59
  def update_page(&block)
74
- rjs(&block)
60
+ rjs(&block).to_s
75
61
  end
76
62
 
77
- # protected
78
-
79
63
  #
80
- # Notifies the scripts collection that the user needs the module
64
+ # Requires the RightJS modules
81
65
  #
82
- def rightjs_include_module(*list)
83
- @_right_scripts ||= []
84
- list.each do |name|
85
- @_right_scripts << name.to_s unless @_right_scripts.include?(name.to_s)
86
- end
66
+ def rightjs_require_module(*list)
67
+ RightRails::Helpers.require_js_module self, *list
87
68
  end
88
69
 
89
- #
90
- # Collects the RightJS unit options out of the given list of options
91
- #
92
- # NOTE: will nuke matching keys out of the original options object
93
- #
94
- # @param user's options
95
- # @param allowed unit options keys
96
- #
97
- def rightjs_unit_options(options, unit_keys)
98
- unit_options = []
99
-
100
- options.dup.each do |key, value|
101
- c_key = key.to_s.camelize.gsub!(/^[A-Z]/){ |m| m.downcase }
102
-
103
- if unit_keys.include?(c_key)
104
- value = options.delete key
105
-
106
- value = case value.class.name.to_sym
107
- when :NilClass then 'null'
108
- when :Symbol then c_key == 'method' ? "'#{value}'" : "#{value}"
109
- when :String then "'#{value}'"
110
- else value.inspect
111
- end
112
-
113
- unit_options << "#{c_key}:#{value}"
114
- end
115
- end
116
-
117
- "{#{unit_options.sort.join(',')}}"
118
- end
119
-
120
- #
121
- # Rails 2 && 3 html-safe string
122
- #
123
- def __rjs_hs(string)
124
- string.send("".respond_to?(:html_safe) ? :html_safe : :to_s) if string
125
- end
126
70
  end