rjs_helpers 0.0.4 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,16 +5,12 @@ RJS Helpers
5
5
 
6
6
  Some helper methods to perform standard JS library tasks from js.erb without having to write actual javascript
7
7
 
8
+ **Important**: This version was made for use with Rails >= 3.1. If you are using Rails 2.3, please take a look
9
+ at the `rails2` branch.
10
+
8
11
  Installation
9
12
  ============
10
13
 
11
- As a plugin
12
- -----------
13
-
14
- To install the plugin in your Rails 2.3 application, simply run
15
-
16
- ruby script/plugin install https://github.com/Stex/rjs_helpers.git
17
-
18
14
  As a gem
19
15
  --------
20
16
 
@@ -26,16 +22,12 @@ or put this into your `Gemfile`:
26
22
 
27
23
  gem 'rjs_helpers'
28
24
 
29
-
30
- This will automatically load the Rails helper into all your controllers.
31
- As explained below, the plugin ships with a default JS adapter for jQuery
32
- which can be automatically copied to your public/javascripts directory with
33
- the following line:
25
+ In this version, RJS helpers is built as a Rails engine,
26
+ so the necessary helper methods and assets are automatically loaded into your application.
34
27
 
35
- ruby script/generate rjs_helpers js
36
-
37
- Now you only have to include this js file into your application layout
38
- and you're good to go.
28
+ You only have to extend your `application.js` file to include the necessary javascript:
29
+
30
+ //= require rjs_helpers
39
31
 
40
32
  Usage
41
33
  =====
@@ -124,16 +116,9 @@ if you have a fixed top navbar (greetings to you, bootstrap).
124
116
 
125
117
  If `:top` is given as the first argument, the page will simply scroll to the very top (+ offset).
126
118
 
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
119
  Examples
136
120
  ========
121
+
137
122
  ```ruby
138
123
  = js_update_element @user, :partial => 'user', :object => @user
139
124
  #=> rjsHelpers.updateElementByDomId('user_123', ...)
@@ -134,7 +134,7 @@ module RjsHelper
134
134
  end
135
135
 
136
136
  def string_args(args)
137
- args.map {|a| a.is_a?(Numeric) ? a : ('"' + fixed_escape_javascript(a.to_s) + '"')}.join(', ')
137
+ args.map {|a| a.is_a?(Numeric) ? a : "'#{a}'"}.join(', ')
138
138
  end
139
139
 
140
140
 
@@ -144,15 +144,6 @@ module RjsHelper
144
144
  # Also, it automatically escapes javascript in the given content
145
145
  #--------------------------------------------------------------
146
146
  def rendered_content(content)
147
- content.is_a?(Hash) ? render(content) : content
148
- end
149
-
150
- #
151
- # The Rails +escape_javascript+ helper does not seem to automatically
152
- # escape unicode newline elements which causes javascript strings
153
- # to break. This method escapes these sequences.
154
- #
155
- def fixed_escape_javascript(text)
156
- escape_javascript(text).gsub("\342\200\250", "
")
147
+ escape_javascript(content.is_a?(Hash) ? render(content) : content)
157
148
  end
158
149
  end
@@ -0,0 +1,4 @@
1
+ module RjsHelpers
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module RjsHelpers
2
- VERSION = '0.0.4'
2
+ VERSION = '1.0'
3
3
  end
data/lib/rjs_helpers.rb CHANGED
@@ -1 +1,2 @@
1
- # RailsJsHelpers
1
+ require 'rjs_helpers/version'
2
+ require 'rjs_helpers/engine' if defined?(::Rails)
data/rjs_helpers.gemspec CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
+ spec.add_dependency 'railties', '>= 3.2', '< 5.0'
22
+
21
23
  spec.add_development_dependency 'bundler', '~> 1.3'
22
24
  spec.add_development_dependency 'rake', '0.9.2.2'
23
25
  spec.add_development_dependency 'barista'
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class RjsHelperTest < ActiveSupport::TestCase
3
+ class JrsHelperTest < ActiveSupport::TestCase
4
4
  # Replace this with your real tests.
5
5
  test "the truth" do
6
6
  assert true
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rjs_helpers
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 0
9
- - 4
10
- version: 0.0.4
9
+ version: "1.0"
11
10
  platform: ruby
12
11
  authors:
13
12
  - Stefan Exner
@@ -15,12 +14,34 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2014-06-05 00:00:00 Z
17
+ date: 2014-03-18 00:00:00 Z
19
18
  dependencies:
20
19
  - !ruby/object:Gem::Dependency
21
- name: bundler
20
+ name: railties
22
21
  prerelease: false
23
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 3
30
+ - 2
31
+ version: "3.2"
32
+ - - <
33
+ - !ruby/object:Gem::Version
34
+ hash: 31
35
+ segments:
36
+ - 5
37
+ - 0
38
+ version: "5.0"
39
+ type: :runtime
40
+ version_requirements: *id001
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ prerelease: false
44
+ requirement: &id002 !ruby/object:Gem::Requirement
24
45
  none: false
25
46
  requirements:
26
47
  - - ~>
@@ -31,11 +52,11 @@ dependencies:
31
52
  - 3
32
53
  version: "1.3"
33
54
  type: :development
34
- version_requirements: *id001
55
+ version_requirements: *id002
35
56
  - !ruby/object:Gem::Dependency
36
57
  name: rake
37
58
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
59
+ requirement: &id003 !ruby/object:Gem::Requirement
39
60
  none: false
40
61
  requirements:
41
62
  - - "="
@@ -48,11 +69,11 @@ dependencies:
48
69
  - 2
49
70
  version: 0.9.2.2
50
71
  type: :development
51
- version_requirements: *id002
72
+ version_requirements: *id003
52
73
  - !ruby/object:Gem::Dependency
53
74
  name: barista
54
75
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
76
+ requirement: &id004 !ruby/object:Gem::Requirement
56
77
  none: false
57
78
  requirements:
58
79
  - - ">="
@@ -62,7 +83,7 @@ dependencies:
62
83
  - 0
63
84
  version: "0"
64
85
  type: :development
65
- version_requirements: *id003
86
+ version_requirements: *id004
66
87
  description: Some helper methods to perform standard JS library tasks from js.erb without having to write actual javascript
67
88
  email:
68
89
  - stexmedia@googlemail.com
@@ -79,16 +100,12 @@ files:
79
100
  - MIT-LICENSE
80
101
  - README.md
81
102
  - Rakefile
82
- - app/coffeescripts/rjs_helper.coffee
103
+ - app/assets/javascripts/rjs_helpers.coffee
83
104
  - app/helpers/rjs_helper.rb
84
- - generators/rjs_helpers/rjs_helpers_generator.rb
85
- - generators/rjs_helpers/templates/assets/js/rjs_helper.js
86
- - init.rb
87
105
  - install.rb
88
106
  - lib/rjs_helpers.rb
107
+ - lib/rjs_helpers/engine.rb
89
108
  - lib/rjs_helpers/version.rb
90
- - lib/tasks/rjs_helpers.rake
91
- - rails/init.rb
92
109
  - rjs_helpers.gemspec
93
110
  - test/rjs_helpers_test.rb
94
111
  - test/test_helper.rb
@@ -122,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
139
  requirements: []
123
140
 
124
141
  rubyforge_project:
125
- rubygems_version: 1.7.2
142
+ rubygems_version: 1.8.22
126
143
  signing_key:
127
144
  specification_version: 3
128
145
  summary: Some helper methods to perform standard JS library tasks from js.erb without having to write actual javascript
@@ -1,13 +0,0 @@
1
- class RjsHelpersGenerator < Rails::Generator::NamedBase
2
- def manifest
3
- record do |m|
4
- m.file File.join('assets', 'js', 'rjs_helper.js'), File.join('public', 'javascripts', 'rjs_helper.js')
5
- end
6
- end
7
-
8
- protected
9
-
10
- def banner
11
- "Usage: #{$0} rjs_helpers js"
12
- end
13
- end
@@ -1,82 +0,0 @@
1
- // Generated by CoffeeScript 1.4.0
2
- (function() {
3
-
4
- window.rjsHelpers = {
5
- updateElement: function(element, content) {
6
- return jQuery(element).html(content);
7
- },
8
- updateElementById: function(element, content) {
9
- return this.updateElement("#" + element, content);
10
- },
11
- replaceElement: function(element, content) {
12
- return jQuery(element).replaceWith(content);
13
- },
14
- replaceElementById: function(element, content) {
15
- return this.replaceElement("#" + element, content);
16
- },
17
- removeElement: function(element) {
18
- return jQuery(element).remove();
19
- },
20
- removeElementById: function(element) {
21
- return this.removeElement("#" + element);
22
- },
23
- appendElement: function(element, content) {
24
- return jQuery(element).append(content);
25
- },
26
- appendElementById: function(element, content) {
27
- return this.appendElement("#" + element, content);
28
- },
29
- prependElement: function(element, content) {
30
- return jQuery(element).prepend(content);
31
- },
32
- prependElementById: function(element, content) {
33
- return this.prependElement("#" + element, content);
34
- },
35
- hideElement: function(element) {
36
- return jQuery(element).hide();
37
- },
38
- hideElementById: function(element) {
39
- return this.hideElement("#" + element);
40
- },
41
- showElement: function(element) {
42
- return jQuery(element).show();
43
- },
44
- showElementById: function(element) {
45
- return this.showElement("#" + element);
46
- },
47
- toggleElement: function(element) {
48
- return jQuery(element).toggle();
49
- },
50
- toggleElementById: function(element) {
51
- return this.toggleElement("#" + element);
52
- },
53
- scrollToElement: function(element, offsetTop) {
54
- if (offsetTop == null) {
55
- offsetTop = 0;
56
- }
57
- jQuery('html, body').animate({
58
- scrollTop: jQuery(element).offset().top - offsetTop
59
- }, 1000);
60
- return false;
61
- },
62
- scrollToElementById: function(element, offsetTop) {
63
- if (offsetTop == null) {
64
- offsetTop = 0;
65
- }
66
- return this.scrollToElement("#" + element, offsetTop);
67
- },
68
- scrollToTop: function(offsetTop) {
69
- if (offsetTop == null) {
70
- offsetTop = 0;
71
- }
72
- jQuery("html, body").animate({
73
- scrollTop: offsetTop
74
- }, 600);
75
- return false;
76
- },
77
- redirectTo: function(url) {
78
- return window.location.href = url;
79
- }
80
- };
81
-
82
- }).call(this);
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require File.dirname(__FILE__) + '/rails/init'
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :rails_js_helpers do
3
- # # Task goes here
4
- # end
data/rails/init.rb DELETED
@@ -1,4 +0,0 @@
1
- #Automatically include the js_erb helper in each controller
2
- ActionController::Base.class_eval do
3
- helper :rjs
4
- end