js_namespace_framework 2.0.0

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.
data/MIT-LICENSE ADDED
@@ -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.
data/README.rdoc ADDED
@@ -0,0 +1,83 @@
1
+ = Js::Namespace::Framework
2
+
3
+ == Use the power of Rails to namespace your JavaScript.
4
+
5
+ * Add
6
+
7
+ <%= init_javascript if requires_javascript? %>
8
+
9
+ to the bottom of your layout.
10
+
11
+ When you need some JS Love on a page
12
+ Lets say
13
+
14
+ :controller => 'messages', :action => 'show'
15
+
16
+ * simply define the following method in the messages_helper.rb
17
+
18
+ def requires_javascript?
19
+ return true if action_is? 'show'
20
+ end
21
+
22
+ * This will generate the following namespaced call.
23
+
24
+ SiteName.controller.action_page();
25
+
26
+ * In this case
27
+
28
+ SiteName.messages.show_page();
29
+
30
+ * Then just define your namespace and method
31
+
32
+ SiteName = {}
33
+
34
+ SiteName.messages = {
35
+
36
+ show_page: function() {
37
+ SiteName.awesomeness.activate();
38
+ }
39
+ }
40
+
41
+
42
+ * If you need some more progressive enhancement on messages.index
43
+ * In the messages_helper.rb
44
+
45
+ def requires_javascript?
46
+ return true if action_is? 'show', 'index'
47
+ end
48
+
49
+
50
+ * In a Js file
51
+
52
+ SiteName = {}
53
+
54
+ SiteName.messages = {
55
+
56
+ show_page: function() {
57
+ SiteName.awesomeness.activate();
58
+ },
59
+
60
+ index_page: function() {
61
+ SiteName.progressively.enhance();
62
+ }
63
+ }
64
+
65
+
66
+ I would recommend creating one Js file per controller
67
+ to keep things nice and neat and using Asset Packager
68
+ to pack everything together for production.
69
+
70
+
71
+ == INSTALL
72
+
73
+ braid add (this) -p
74
+
75
+ get braid if you do not have it.
76
+
77
+
78
+ * Define
79
+ SITE_NAME
80
+ somewhere
81
+
82
+
83
+ Copyright (c) 2009 [Brent Greeff], 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 js_namespace_framework 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 js_namespace_framework plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'JsNamespaceFramework'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
@@ -0,0 +1,3 @@
1
+ require 'js_namespace_framework/helper_methods'
2
+
3
+ ActionView::Base.send :include, Js::Namespace::Framework
@@ -0,0 +1,35 @@
1
+ module Js
2
+ module Namespace
3
+ module Framework
4
+
5
+ def init_javascript
6
+ unless defined? SITE_NAME
7
+ raise Js::Namespace::Framework::Setup::Error, 'Please define SITE_NAME'
8
+ end
9
+
10
+ action = params[:action]
11
+ action = 'new' if params[:action].eql? 'create'
12
+ action = 'edit' if params[:action].eql? 'update'
13
+
14
+ javascript_tag("#{SITE_NAME}.#{params[:controller]}.#{action}_page();")
15
+ end
16
+
17
+ def requires_javascript?
18
+ false
19
+ end
20
+
21
+ def action_is?(*args)
22
+ return true if args.include? params[:action]
23
+
24
+ return true if args.include? 'new' and params[:action].eql? 'create'
25
+ return true if args.include? 'edit' and params[:action].eql? 'update'
26
+
27
+ return false
28
+ end
29
+
30
+ module Setup
31
+ class Error < RuntimeError; end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class JsNamespaceFrameworkTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: js_namespace_framework
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease: false
6
+ segments:
7
+ - 2
8
+ - 0
9
+ - 0
10
+ version: 2.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Brent Greeff
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-30 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Use the power of Rails to namespace your JavaScript.
23
+ email: email@brentgreeff.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - MIT-LICENSE
30
+ - README.rdoc
31
+ files:
32
+ - MIT-LICENSE
33
+ - README.rdoc
34
+ - Rakefile
35
+ - VERSION
36
+ - lib/js_namespace_framework.rb
37
+ - lib/js_namespace_framework/helper_methods.rb
38
+ - test/js_namespace_framework_test.rb
39
+ - test/test_helper.rb
40
+ has_rdoc: true
41
+ homepage: http://github.com/brentgreeff/js_namespace_framework
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --charset=UTF-8
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.3.7
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Use the power of Rails to namespace your JavaScript.
74
+ test_files: []
75
+