js_namespace 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ *.gem
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 [Brent Greeff]
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.
@@ -0,0 +1,90 @@
1
+ = Js::Namespace::Framework
2
+
3
+ == Use the power of Rails to namespace your JavaScript.
4
+
5
+ == INSTALL
6
+
7
+ gem install js_namespace_framework
8
+
9
+ (or use bundler)
10
+
11
+ * Define
12
+ SITE_NAME
13
+
14
+ somewhere
15
+
16
+ probably:
17
+ config/initializers
18
+
19
+
20
+ == Usage
21
+
22
+ * Add
23
+
24
+ <%= initialize_javascript if requires_javascript? %>
25
+
26
+ to the bottom of your layout.
27
+
28
+ When you need some JS Love on a page
29
+ Lets say
30
+
31
+ :controller => 'messages', :action => 'show'
32
+
33
+ * simply define the following method in the messages_helper.rb
34
+
35
+ def requires_javascript?
36
+ return true if action_is? 'show'
37
+ end
38
+
39
+ * This will generate the following namespaced call.
40
+
41
+ SiteName.controller.action_page();
42
+
43
+ * In this case
44
+
45
+ SiteName.messages.show_page();
46
+
47
+ * Then just define your namespace and method
48
+
49
+ SiteName = {}
50
+
51
+ SiteName.messages = {
52
+
53
+ show_page: function() {
54
+ SiteName.awesomeness.activate();
55
+ }
56
+ }
57
+
58
+
59
+ * If you need some more progressive enhancement on messages.index
60
+ * In the messages_helper.rb
61
+
62
+ def requires_javascript?
63
+ return true if action_is? 'show', 'index'
64
+ end
65
+
66
+
67
+ * In a Js file
68
+
69
+ SiteName = {}
70
+
71
+ SiteName.messages = {
72
+
73
+ show_page: function() {
74
+ SiteName.awesomeness.activate();
75
+ },
76
+
77
+ index_page: function() {
78
+ SiteName.progressively.enhance();
79
+ }
80
+ }
81
+
82
+
83
+ I would recommend creating one Js file per controller
84
+ to keep things nice and neat and using Asset Packager
85
+ to pack everything together for production.
86
+
87
+
88
+
89
+
90
+ Copyright (c) 2009 [Brent Greeff], released under the MIT license
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/js_namespace/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Phyo"]
6
+ gem.authors = ["Brent Greeff", "Phyo"]
7
+ gem.email = ["email@brentgreeff.com", "kophyo48@gmail.com"]
8
+
9
+ gem.description = %q{Use the power of Rails to namespace your JavaScript.}
10
+ gem.summary = %q{Use the power of Rails to namespace your JavaScript.}
11
+
12
+ gem.homepage = %q{http://github.com/brentgreeff/js_namespace_framework}
13
+
14
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ gem.name = "js_namespace"
18
+ gem.require_paths = ["lib"]
19
+ gem.version = JsNamespace::VERSION
20
+ end
@@ -0,0 +1,51 @@
1
+ module JsNamespace
2
+ def site_name
3
+ 'Site'
4
+ end
5
+
6
+ def initialize_javascript
7
+ javascript_tag("
8
+ if (typeof(#{site_name}) !== 'undefined'){
9
+ if (typeof(#{site_name}.#{js_controller}) !== 'undefined') {
10
+ #{site_name}.#{js_controller}.#{js_page}();
11
+ }
12
+ }
13
+ ")
14
+
15
+ end
16
+
17
+ def requires_javascript?
18
+ false
19
+ end
20
+
21
+ def js_controller
22
+ params[:controller] + "Controller"
23
+ end
24
+
25
+ def js_action
26
+ if params[:action] == 'create'
27
+ 'new'
28
+ elsif params[:action] == 'update'
29
+ 'edit'
30
+ else
31
+ params[:action]
32
+ end
33
+ end
34
+
35
+ def js_page
36
+ "#{js_action}Page"
37
+ end
38
+
39
+ private
40
+ def action_is?(*args)
41
+ return true if args.include? params[:action]
42
+
43
+ return true if args.include? 'new' and params[:action].eql? 'create'
44
+ return true if args.include? 'edit' and params[:action].eql? 'update'
45
+
46
+ return false
47
+ end
48
+ end
49
+
50
+ ActionView::Base.send :include, JsNamespace
51
+
@@ -0,0 +1,3 @@
1
+ module JsNamespace
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: js_namespace
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brent Greeff
9
+ - Phyo
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-05-10 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: Use the power of Rails to namespace your JavaScript.
16
+ email:
17
+ - email@brentgreeff.com
18
+ - kophyo48@gmail.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - .gitignore
24
+ - MIT-LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - VERSION
28
+ - js_namespace.gemspec
29
+ - lib/js_namespace.rb
30
+ - lib/js_namespace/version.rb
31
+ homepage: http://github.com/brentgreeff/js_namespace_framework
32
+ licenses: []
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 1.8.17
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: Use the power of Rails to namespace your JavaScript.
55
+ test_files: []