rails-js 0.1.0 → 0.1.1

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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. metadata +7 -71
  3. data/.gitignore +0 -6
  4. data/.travis.yml +0 -3
  5. data/Gemfile +0 -14
  6. data/Gemfile.lock +0 -127
  7. data/MIT-LICENSE +0 -20
  8. data/README.md +0 -158
  9. data/Rakefile +0 -25
  10. data/VERSION +0 -1
  11. data/app/assets/javascripts/rails.js +0 -327
  12. data/lib/rails/js.rb +0 -8
  13. data/lib/rails/js/engine.rb +0 -10
  14. data/lib/rails/js/version.rb +0 -5
  15. data/lib/rails/js/view_helpers.rb +0 -23
  16. data/rails-js.gemspec +0 -24
  17. data/test/dummy/README.rdoc +0 -28
  18. data/test/dummy/Rakefile +0 -6
  19. data/test/dummy/app/assets/images/.keep +0 -0
  20. data/test/dummy/app/assets/javascripts/application.js +0 -14
  21. data/test/dummy/app/assets/javascripts/testing.js +0 -2
  22. data/test/dummy/app/assets/stylesheets/application.css +0 -15
  23. data/test/dummy/app/controllers/application_controller.rb +0 -5
  24. data/test/dummy/app/controllers/concerns/.keep +0 -0
  25. data/test/dummy/app/controllers/testing_controller.rb +0 -6
  26. data/test/dummy/app/helpers/application_helper.rb +0 -2
  27. data/test/dummy/app/helpers/testing_helper.rb +0 -2
  28. data/test/dummy/app/mailers/.keep +0 -0
  29. data/test/dummy/app/models/.keep +0 -0
  30. data/test/dummy/app/models/concerns/.keep +0 -0
  31. data/test/dummy/app/views/layouts/application.html.erb +0 -15
  32. data/test/dummy/app/views/testing/index.html.erb +0 -0
  33. data/test/dummy/bin/bundle +0 -3
  34. data/test/dummy/bin/rails +0 -4
  35. data/test/dummy/bin/rake +0 -4
  36. data/test/dummy/config.ru +0 -4
  37. data/test/dummy/config/application.rb +0 -22
  38. data/test/dummy/config/boot.rb +0 -5
  39. data/test/dummy/config/database.yml +0 -25
  40. data/test/dummy/config/environment.rb +0 -5
  41. data/test/dummy/config/environments/development.rb +0 -37
  42. data/test/dummy/config/environments/production.rb +0 -83
  43. data/test/dummy/config/environments/test.rb +0 -39
  44. data/test/dummy/config/initializers/assets.rb +0 -3
  45. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  46. data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
  47. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  48. data/test/dummy/config/initializers/inflections.rb +0 -16
  49. data/test/dummy/config/initializers/mime_types.rb +0 -4
  50. data/test/dummy/config/initializers/session_store.rb +0 -3
  51. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  52. data/test/dummy/config/locales/en.yml +0 -23
  53. data/test/dummy/config/routes.rb +0 -4
  54. data/test/dummy/config/secrets.yml +0 -22
  55. data/test/dummy/lib/assets/.keep +0 -0
  56. data/test/dummy/public/404.html +0 -67
  57. data/test/dummy/public/422.html +0 -67
  58. data/test/dummy/public/500.html +0 -66
  59. data/test/dummy/public/favicon.ico +0 -0
  60. data/test/dummy/spec/javascripts/rails-js_spec.js +0 -165
  61. data/test/dummy/spec/javascripts/spec_helper.js +0 -31
  62. data/test/dummy/spec/teaspoon_env.rb +0 -13
  63. data/test/dummy/test/helpers/testing_helper_test.rb +0 -4
  64. data/test/teaspoon_env.rb +0 -24
  65. data/test/test_helper.rb +0 -18
  66. data/test/testing_controller_test.rb +0 -12
data/Rakefile DELETED
@@ -1,25 +0,0 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
6
-
7
- Bundler::GemHelper.install_tasks
8
-
9
- require 'rake/testtask'
10
-
11
- Rake::TestTask.new(:test) do |t|
12
- t.libs << 'lib'
13
- t.libs << 'test'
14
- t.pattern = 'test/**/*_test.rb'
15
- t.verbose = false
16
- end
17
-
18
- # teaspoon must be executed inside the dummy rails app
19
- task :teaspoon do
20
- Dir.chdir('test/dummy/')
21
- sh 'bundle exec rake teaspoon'
22
- end
23
-
24
- # add teaspoon to default tasks
25
- task default: :test
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0
@@ -1,327 +0,0 @@
1
- (function(window, document) {
2
-
3
- /*
4
- * All the global stuff (helpers, data, hooks) is stored
5
- * locally in this closure so we cannot do anything wrong
6
- */
7
- var controllers = {},
8
- globalHelpers = {},
9
- namespaceHooks = {},
10
- data = {},
11
- beforeAll = null;
12
-
13
- /*
14
- * Singleton that stores functions to create your apps' structure
15
- */
16
- Rails = window.Rails || {};
17
-
18
- /*
19
- * For testing. We want to start each test with emtpiness.
20
- */
21
- Rails.clear = function() {
22
- controllers = {};
23
- globalHelpers = {};
24
- namespaceHooks = {};
25
- data = {};
26
- beforeAll = null;
27
- };
28
-
29
- /*
30
- * Creates a Rails application (the javascript part!)
31
- *
32
- * Pass global helper and initial data as params
33
- */
34
- Rails.app = function(helpers, initialData, beforeHook) {
35
-
36
- /*
37
- * Store everything in our local variables
38
- */
39
- globalHelpers = helpers;
40
- data = initialData;
41
- beforeAll = beforeHook;
42
-
43
- /*
44
- * Set event listener to execute controllers' javascript
45
- *
46
- * There might be cases where we do not want to execute
47
- * DOM-related js (e.g. javascript unit-tests).
48
- * Set Rails.config.test to disable action execution.
49
- */
50
- listener = function(event) {
51
-
52
- if (Rails.config && Rails.config.test) {
53
- return;
54
- }
55
-
56
- Rails.execute();
57
- };
58
-
59
- document.addEventListener("DOMContentLoaded", listener);
60
-
61
- /*
62
- * Add support to Turbolinks page changes
63
- */
64
- if (typeof Turbolinks !== 'undefined') {
65
- document.addEventListener('page:load', listener);
66
- }
67
- };
68
-
69
- /*
70
- * Adds a controller.
71
- * Controllers are used to apply javascript in rails routes.
72
- * Example:
73
- *
74
- * Rails.controller('users', {
75
- *
76
- * new: function() {
77
- * // Executed on users/new
78
- * }
79
- * });
80
- */
81
- Rails.controller = function(name, actions, helpers) {
82
-
83
- /*
84
- * Should not be able to define controller (and helpers) twice
85
- */
86
- if (controllers[name]) {
87
- throw ['Controller \'', name,
88
- '\' is already defined! Please use a namespace'].join('');
89
- }
90
-
91
- /*
92
- * Store controller & helpers in our local closure
93
- */
94
- controllers[name] = actions;
95
- controllers[name].helpers = helpers;
96
- },
97
-
98
- /*
99
- * Execute the actual controller action.
100
- * e.g. will execute controller.users.index()
101
- * when on #users/index
102
- */
103
- Rails.execute = function() {
104
-
105
- /*
106
- * Make sure rails.js has been properly added to the layout
107
- */
108
- if (!(this.config && this.config.controller && this.config.action)) {
109
-
110
- throw ['No action or controller given.',
111
- 'It seems like you forgot to add rails.js to your layouts\' header.'].join(' ');
112
- }
113
-
114
- var controllerName = this.config.controller,
115
- namespaceHook,
116
- controller;
117
-
118
- /*
119
- * Execute beforeAll() hook if defined
120
- */
121
- if (beforeAll && typeof(beforeAll) == 'function') {
122
- beforeAll();
123
- }
124
-
125
- /*
126
- * Take care of namespace (e.g. admin/users)
127
- */
128
- if (this.config.namespace) {
129
- controllerName = this.config.namespace + '/' + controllerName;
130
-
131
- /*
132
- * Execute namespace hook if we defined one
133
- */
134
- namespaceHook = namespaceHooks[this.config.namespace];
135
- if (namespaceHook && typeof(namespaceHook) == 'function') {
136
- namespaceHook();
137
- }
138
- }
139
-
140
- /*
141
- * Find controller and execute method
142
- */
143
- var controller = controllers[controllerName];
144
- if (controller && controller[this.config.action] &&
145
- typeof(controller[this.config.action]) == 'function') {
146
-
147
- controller[this.config.action](controller.helpers);
148
- }
149
- };
150
-
151
- /*
152
- * Defines a namespace hook which will be executed when
153
- * we are in the namespace of that hook.
154
- *
155
- * For example:
156
- * When we define a namespace for 'admin'
157
- * the function will be executed on all controllers in that namespace.
158
- * (e.g. Admin::UsersController, Admin::SettingsController, etc...)
159
- */
160
- Rails.namespace = function(name, block) {
161
-
162
- /*
163
- * Should not be able to define controller (and helpers) twice
164
- */
165
- if (namespaceHooks[name]) {
166
- throw ['Namespace \'', name, '\' is already defined!'].join('');
167
- }
168
-
169
- namespaceHooks[name] = block;
170
- };
171
-
172
-
173
- /*
174
- * Global Singleton to store variables and functions
175
- * that you need all over your javascript codebase.
176
- *
177
- * Also contains global helpers, so to prevent conflicts
178
- * we save global variables by using this singleton as a function.
179
- *
180
- * R('foo'); // Gets window.R.data.foo
181
- * R('foo', 'bar'); // Sets window.R.data.foo
182
- */
183
- R = function(key, val) {
184
-
185
- /*
186
- * It's possible to go multiple layers with one call, e.g.
187
- * R('foo.bar.baz');
188
- *
189
- * Or you can set things at paths which are not there:
190
- * // foo and bar will be created as empty objects
191
- * R('foo.bar.baz', 'foo');
192
- *
193
- */
194
- var steps = key.split('.'),
195
- step = data,
196
- i;
197
-
198
- if (arguments.length == 2) {
199
- for (i = 0; i < steps.length-1; i++) {
200
- if (!step[steps[i]]) {
201
- step[steps[i]] = {};
202
- }
203
-
204
- step = step[steps[i]];
205
- }
206
-
207
- step[steps[steps.length -1]] = val;
208
-
209
- } else {
210
- for (i = 0; i < steps.length; i++) {
211
- step = step[steps[i]];
212
- if (!step) {
213
- break;
214
- }
215
-
216
- }
217
- return step;
218
- }
219
- };
220
-
221
- /*
222
- * Execute a helper of a foreign controller
223
- *
224
- * e.g.
225
- * Rails.helper('admin/users', 'method', [arg1, arg2, arg3]);
226
- * or
227
- * Rails.helper('entities', 'method', arg1, arg2, arg3);
228
- */
229
- R.helper = function(controllerName, helperName) {
230
-
231
- var controller,
232
- helper,
233
- context,
234
- args = Array.prototype.slice.call(arguments, 2);
235
-
236
- /*
237
- * Treat 3rd argument as arguments for helper if it is an Array
238
- */
239
- if (args.length == 1 && args[0] instanceof Array) {
240
- args = args[0];
241
- }
242
-
243
- /*
244
- * Choose global helper if controllerName is not given
245
- */
246
- if (controllerName) {
247
- controller = controllers[controllerName];
248
- helper = controller.helpers[helperName];
249
- } else {
250
- helper = globalHelpers[helperName];
251
- }
252
-
253
- /*
254
- * Make sure our helper exists
255
- */
256
- if (!(helper && typeof(helper) == 'function')) {
257
- if (controllerName) {
258
- throw ['Helper \'', helperName, '\' not defined for controller \'',
259
- controllerName, '\''].join('');
260
- } else {
261
- throw ['Global helper \'', helperName, '\' not defined'].join('');
262
- }
263
- }
264
-
265
- /*
266
- * Choose context, either some controllers' helpers or
267
- * the globalHelpers object
268
- */
269
- context = controller ? controller.helpers : globalHelpers;
270
-
271
- /*
272
- * Execute helper in context with arguments
273
- */
274
- return helper.apply(context, args);
275
- };
276
-
277
- /*
278
- * Execute a global helper
279
- *
280
- * Global helpers are defined when the Rails.app is created
281
- */
282
- R.global = function(helperName) {
283
- return this.helper(undefined, helperName, Array.prototype.slice.call(arguments, 1));
284
- };
285
-
286
- /*
287
- * Executes a controller action
288
- * (to execute the same javascript in a different controller)
289
- */
290
- R.action = function(action) {
291
-
292
- /*
293
- * Arguments are either controller and action or the
294
- * familliar rails syntax:
295
- *
296
- * R.action('users', 'index');
297
- * R.action('users#index');
298
- */
299
- var controller,
300
- controllerName = arguments[0],
301
- actionName = arguments[1];
302
-
303
- if (action.indexOf('#') !== -1) {
304
- controllerName = action.split('#')[0];
305
- actionName = action.split('#')[1];
306
- }
307
-
308
- /*
309
- * Make sure controller and action exist
310
- */
311
- controller = controllers[controllerName];
312
-
313
- if (!controller) {
314
- throw ['Attempting to call action \'', controllerName, '#', actionName,
315
- '\', but Controller \'', controllerName, '\' is not defined!'].join('');
316
- } else if (!controller[actionName] || !(typeof(controller[actionName]) == 'function')) {
317
- throw ['Attempting to call action \'', controllerName, '#', actionName,
318
- '\', but Action \'', actionName, '\' is not defined!'].join('');
319
- }
320
-
321
- /*
322
- * Execute controller action with helpers as argument
323
- */
324
- controller[actionName](controller.helper);
325
- };
326
-
327
- })(window, window.document);
@@ -1,8 +0,0 @@
1
- module Rails
2
- module JS
3
- if defined?(::Rails)
4
- require_relative 'js/view_helpers'
5
- require_relative 'js/engine'
6
- end
7
- end
8
- end
@@ -1,10 +0,0 @@
1
- module Rails
2
- module JS
3
- class Engine < ::Rails::Engine
4
- initializer "rails-js.view_helpers" do |app|
5
- # include view helpers
6
- ActionView::Base.send :include, ViewHelpers
7
- end
8
- end
9
- end
10
- end
@@ -1,5 +0,0 @@
1
- module Rails
2
- module JS
3
- VERSION = "0.1.0"
4
- end
5
- end
@@ -1,23 +0,0 @@
1
- module Rails
2
- module JS
3
- module ViewHelpers
4
- def rails_js
5
-
6
- namespace = controller_path.split('/').reject do |el|
7
- el == controller_name
8
- end.join
9
-
10
- raw [
11
- '<script type="text/javascript">',
12
- 'window.Rails = window.Rails || {};',
13
- 'Rails.config = {',
14
- " controller: '#{controller_name}',",
15
- " namespace: '#{namespace}',",
16
- " action: '#{action_name}'",
17
- '};',
18
- '</script>'
19
- ].join("\n")
20
- end
21
- end
22
- end
23
- end
@@ -1,24 +0,0 @@
1
- $:.push File.expand_path("../lib", __FILE__)
2
-
3
- # Maintain your gem's version:
4
- require "rails/js/version"
5
-
6
- Gem::Specification.new do |s|
7
- s.name = 'rails-js'
8
- s.version = Rails::JS::VERSION
9
- s.date = Time.now.strftime("%Y-%m-%d")
10
- s.summary = "A new approach to structure your javascript in non single-page Rails apps"
11
- s.description = "Divide your javascript like you divide your ruby code. Put it in controllers and actions and write clean, scalable code."
12
- s.authors = ["Finn-Lenanrt Heemeyer"]
13
- s.email = 'finn@heemeyer.net'
14
- s.files = `git ls-files`.split("\n")
15
- s.require_paths = ['lib']
16
- s.homepage = 'http://rubygems.org/gems/rails-js'
17
- s.license = 'MIT'
18
-
19
- s.add_dependency "rails", "~> 4"
20
- s.add_development_dependency "sqlite3", "~> 1.3"
21
- s.add_development_dependency "teaspoon", "~> 0.8"
22
- s.add_development_dependency "poltergeist", "~> 1.5"
23
- s.add_development_dependency "coveralls", "~> 0.7"
24
- end
@@ -1,28 +0,0 @@
1
- == README
2
-
3
- This README would normally document whatever steps are necessary to get the
4
- application up and running.
5
-
6
- Things you may want to cover:
7
-
8
- * Ruby version
9
-
10
- * System dependencies
11
-
12
- * Configuration
13
-
14
- * Database creation
15
-
16
- * Database initialization
17
-
18
- * How to run the test suite
19
-
20
- * Services (job queues, cache servers, search engines, etc.)
21
-
22
- * Deployment instructions
23
-
24
- * ...
25
-
26
-
27
- Please feel free to use a different markup language if you do not plan to run
28
- <tt>rake doc:app</tt>.