rails_jskit 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,98 @@
1
+ module Jskit
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ def create_controllers_directory
7
+ empty_directory "app/assets/javascripts/controllers"
8
+ end
9
+
10
+ def copy_controllers
11
+ template "app/assets/javascripts/controllers/application_controller.js"
12
+ end
13
+
14
+ def add_js_to_manifest
15
+ add_rails_jskit if manifest?
16
+ end
17
+
18
+ def append_jskit_to_application_layout
19
+ send("append_jskit_method_to_application_layout_#{layout_extension}") unless jskit_method_exists?
20
+ end
21
+
22
+ def create_initializer
23
+ template "config/initializers/rails_jskit.rb"
24
+ end
25
+
26
+ private
27
+
28
+ def add_rails_jskit
29
+ return if rails_jskit?
30
+ if require_tree?
31
+ gsub_file(js_manifest, /\/\/= require_tree \./, "//= require rails_jskit\n//= require_tree ./controllers\n")
32
+ else
33
+ append_to_file(js_manifest, "//= require rails_jskit\n//= require_tree ./controllers\n")
34
+ end
35
+ end
36
+
37
+ def jskit_method_snippet
38
+ method = case layout_extension
39
+ when :erb
40
+ "<%= jskit %>"
41
+ when :haml
42
+ "= jskit"
43
+ end
44
+
45
+ "\n#{body_indentation}#{method}\n"
46
+ end
47
+
48
+ def jskit_method_exists?
49
+ !!layout_file_content.match(/\= jskit/)
50
+ end
51
+
52
+ def layout_file_content
53
+ File.exists?(layout_file) ? File.read(layout_file) : ""
54
+ end
55
+
56
+ def body_indentation
57
+ "#{layout_file_content.match(/^(\s+)%body/)[1]} "
58
+ end
59
+
60
+ def layout_file
61
+ @layout_file ||= Dir["app/views/layouts/application.html*"].first
62
+ end
63
+
64
+ def append_jskit_method_to_application_layout_erb
65
+ insert_into_file layout_file, jskit_method_snippet, before: "</body>"
66
+ end
67
+
68
+ def append_jskit_method_to_application_layout_haml
69
+ append_to_file layout_file, jskit_method_snippet
70
+ end
71
+
72
+ def layout_extension
73
+ File.extname(layout_file).gsub(/^\./, "").to_sym
74
+ end
75
+
76
+ def js_manifest
77
+ "app/assets/javascripts/application.js"
78
+ end
79
+
80
+ def add_js_to_manifest
81
+ if File.exists? js_manifest
82
+ if has_jquery?
83
+ insert_into_file js_manifest, "//= require lodash\n", before: "//= require jquery\n" unless has_lodash?
84
+ else
85
+ append_to_file js_manifest, "//= require lodash\n//= require jquery\n"
86
+ end
87
+ append_to_file js_manifest, "//= require rails_jskit\n//= require_tree ./controllers\n"
88
+ end
89
+ end
90
+
91
+ private
92
+
93
+ def application_js
94
+ @application_js ||= File.read js_manifest
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,5 @@
1
+ <%= RailsJskit.configuration.app_namespace %>.createController("Application", {
2
+ all: function() {
3
+ console.log("JSkit installed!");
4
+ }
5
+ });
@@ -0,0 +1,4 @@
1
+ RailsJskit.configure do |config|
2
+ # Change the JSkit Application global namespace (defaults to `App`)
3
+ # config.app_namespace = 'App'
4
+ end
@@ -0,0 +1,9 @@
1
+ module Jskit
2
+ # @private
3
+ module Generators
4
+ # @private
5
+ class Base < ::Rails::Generators::NamedBase
6
+ source_root File.expand_path('../templates', __FILE__)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module RailsJskit
2
+ class Configuration
3
+ attr_accessor :app_namespace
4
+
5
+ def initialize
6
+ self.app_namespace = "App"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module RailsJskit
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace RailsJskit
4
+ config.to_prepare do
5
+ decorators_path = File.join(RailsJskit::Engine.config.root, "app", "decorators", "**", "rails_jskit", "**", "*_decorator.rb")
6
+ Dir.glob(decorators_path).each do |decorator|
7
+ require_dependency(decorator)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module RailsJskit
2
+ VERSION = File.read(File.join(File.expand_path("../../..", __FILE__), "VERSION"))
3
+ end
@@ -0,0 +1,16 @@
1
+ require "rails_jskit/engine"
2
+ require "rails_jskit/configuration"
3
+
4
+ module RailsJskit
5
+ class << self
6
+ attr_accessor :configuration
7
+
8
+ def configure(&block)
9
+ fail ArgumentError, "RailsJskit#configure requires a block" if block.nil?
10
+ self.configuration = Configuration.new
11
+ block.call(configuration)
12
+ end
13
+ end
14
+ end
15
+
16
+ RailsJskit.configuration = RailsJskit::Configuration.new
@@ -0,0 +1,59 @@
1
+ require "rails_helper"
2
+
3
+ class OrdersController < ApplicationController
4
+ end
5
+
6
+ describe OrdersController, type: :controller do
7
+ shared_examples "a payload setter" do |payload_type|
8
+ describe "#set_#{payload_type}_payload" do
9
+ it "sets the #{payload_type}_payload to an array of the passed arguments" do
10
+ controller.send("set_#{payload_type}_payload", "foo")
11
+ expect(assigns("#{payload_type}_payload")).to eq(', "foo"')
12
+
13
+ controller.send("set_#{payload_type}_payload", "foo", "bar", "baz")
14
+ expect(assigns("#{payload_type}_payload")).to eq(', "foo", "bar", "baz"')
15
+
16
+ controller.send("set_#{payload_type}_payload", ["foo", "bar", "baz"])
17
+ expect(assigns("#{payload_type}_payload")).to eq(', ["foo","bar","baz"]')
18
+ end
19
+ end
20
+ end
21
+
22
+ it_behaves_like "a payload setter", :action
23
+ it_behaves_like "a payload setter", :controller
24
+ it_behaves_like "a payload setter", :app
25
+
26
+ describe "#jskit" do
27
+ let(:view_context) { controller.view_context }
28
+
29
+ before do
30
+ controller.action_name = "action"
31
+ end
32
+
33
+ it "returns a script tag with the global event and the controller event" do
34
+ app_event = "App.Dispatcher.trigger(\"controller:application:all\", \"baz\");"
35
+ controller_event = "App.Dispatcher.trigger(\"controller:orders:all\", \"bar\");"
36
+ action_event = "App.Dispatcher.trigger(\"controller:orders:action\", \"foo\");"
37
+ expected_js = view_context.javascript_tag([app_event, controller_event, action_event].join("\n"))
38
+
39
+ controller.set_action_payload("foo")
40
+ controller.set_controller_payload("bar")
41
+ controller.set_app_payload("baz")
42
+
43
+ expect(controller.jskit).to eq(expected_js)
44
+ end
45
+
46
+ it "is exposed as a helper method" do
47
+ expect(controller.view_context.jskit).to eq(controller.jskit)
48
+ end
49
+
50
+ it "namespaces events based on the config" do
51
+ app_event = "App.Dispatcher.trigger(\"some_namespace:controller:application:all\");"
52
+ controller_event = "App.Dispatcher.trigger(\"some_namespace:controller:orders:all\");"
53
+ action_event = "App.Dispatcher.trigger(\"some_namespace:controller:orders:action\");"
54
+ expected_js = view_context.javascript_tag([app_event, controller_event, action_event].join("\n"))
55
+
56
+ expect(controller.jskit(namespace: "some_namespace")).to eq(expected_js)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,12 @@
1
+ require "rails_helper"
2
+
3
+ describe RailsJskit::Configuration do
4
+ it "has s default app_namespace" do
5
+ expect(subject.app_namespace).to eq("App")
6
+ end
7
+
8
+ it "allows you to set the app_namespace" do
9
+ subject.app_namespace = "Test"
10
+ expect(subject.app_namespace).to eq("Test")
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require "rails_helper"
2
+
3
+ describe RailsJskit do
4
+ describe "#configure" do
5
+ it "allows you to set configuration values" do
6
+ RailsJskit.configure do |config|
7
+ config.app_namespace = "Test"
8
+ end
9
+ expect(subject.configuration.app_namespace).to eq("Test")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ require "rails_helper"
2
+
3
+ describe RailsJskit::VERSION do
4
+ it "reads the version from the VERSION file" do
5
+ expect(RailsJskit::VERSION).to eq(File.read(File.join(File.expand_path("../../..", __FILE__), "VERSION")))
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_jskit
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dayton Nolan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-nav
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-doc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: fuubar
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
111
+ description: rails_jskit provides jskit.js to the asset pipeline and allows seamless
112
+ event dispatching from your rails application to jskit.
113
+ email:
114
+ - daytonn@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - LICENSE
120
+ - README.md
121
+ - app/assets/javascripts/jskit.js
122
+ - app/assets/javascripts/rails_jskit.js.erb
123
+ - app/decorators/controllers/rails_jskit/application_controller_decorator.rb
124
+ - lib/generators/jskit/USAGE
125
+ - lib/generators/jskit/controller/templates/app/assets/javascripts/controllers/controller.js
126
+ - lib/generators/jskit/install/USAGE
127
+ - lib/generators/jskit/install/install_generator.rb
128
+ - lib/generators/jskit/install/templates/app/assets/javascripts/controllers/application_controller.js
129
+ - lib/generators/jskit/install/templates/config/initializers/rails_jskit.rb
130
+ - lib/generators/jskit/jskit_generator.rb
131
+ - lib/rails_jskit.rb
132
+ - lib/rails_jskit/configuration.rb
133
+ - lib/rails_jskit/engine.rb
134
+ - lib/rails_jskit/version.rb
135
+ - spec/controllers/application_controller_spec.rb
136
+ - spec/lib/configuration_spec.rb
137
+ - spec/lib/jskit_rails_spec.rb
138
+ - spec/lib/version_spec.rb
139
+ homepage: https://github.com/daytonn/rails_jskit
140
+ licenses:
141
+ - Apache 2.0
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.2.2
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Gem that provides Rails integration for jskit
163
+ test_files:
164
+ - spec/controllers/application_controller_spec.rb
165
+ - spec/lib/configuration_spec.rb
166
+ - spec/lib/jskit_rails_spec.rb
167
+ - spec/lib/version_spec.rb
168
+ has_rdoc: