happy_place 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/happy_place.gemspec +25 -0
- data/lib/happy_place/controller.rb +51 -0
- data/lib/happy_place/railtie.rb +13 -0
- data/lib/happy_place/version.rb +3 -0
- data/lib/happy_place.rb +8 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9a0ca9961aa7ce72e1430811b7ddc2fde64b43b4
|
4
|
+
data.tar.gz: ce2bcc45125449f60a1fba8bb293286cce344eb2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cee773a6407f2021bdab9608ab0409adb95290839802de7a76fc80caf7de299839ecbc7130ef0f1b3d97abe66d99191f0f2eeab6181ecad3b2e837760dc3f9e2
|
7
|
+
data.tar.gz: e7615e937d451b6c695cfb698c180223a61e71892b6fd5c40ce65de7d399612fda8d9a5109e83b766313595992db8bb4a0ff06953aa1f7a4bf7287dc10db2804
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Mike Piccolo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# HappyPlace
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'happy_place'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install happy_place
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/happy_place/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/happy_place.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'happy_place/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "happy_place"
|
8
|
+
spec.version = HappyPlace::VERSION
|
9
|
+
spec.authors = ["Mike Piccolo"]
|
10
|
+
spec.email = ["mpiccolo@newleaders.com"]
|
11
|
+
spec.summary = %q{A happy_place for Rails and JS}
|
12
|
+
spec.description = %q{Use javascript in rails in a railsy way.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split("\n")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "rails", ">= 3.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module HappyPlace
|
2
|
+
module Controller
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
# included do
|
6
|
+
# # anything you would want to do in every controller, for example: add a class attribute
|
7
|
+
# class_attribute :class_attribute_available_on_every_controller, instance_writer: false
|
8
|
+
# end
|
9
|
+
|
10
|
+
# module ClassMethods
|
11
|
+
# # notice: no self.method_name here, because this is being extended because ActiveSupport::Concern was extended
|
12
|
+
|
13
|
+
# end
|
14
|
+
|
15
|
+
# instance methods to go on every controller go here
|
16
|
+
def js(js_class: nil, method: nil, partial: nil)
|
17
|
+
return unless [:js, :html].include?(request.format.to_sym)
|
18
|
+
|
19
|
+
js_class ||= self.class.name.gsub("::", ".")
|
20
|
+
method ||= action_name
|
21
|
+
|
22
|
+
if partial.present?
|
23
|
+
appendable = (render_to_string partial: partial).gsub("\n", "")
|
24
|
+
arg = "('#{appendable}');"
|
25
|
+
else
|
26
|
+
arg = "()"
|
27
|
+
end
|
28
|
+
|
29
|
+
class_method = [js_class, method].join(".")
|
30
|
+
if request.format.to_sym == :js
|
31
|
+
render js: class_method + arg
|
32
|
+
elsif request.format.to_sym == :html
|
33
|
+
render
|
34
|
+
response_body = response.body
|
35
|
+
before_body_end_index = response_body.rindex('</body>')
|
36
|
+
|
37
|
+
if before_body_end_index.present?
|
38
|
+
before_body = response_body[0, before_body_end_index].html_safe
|
39
|
+
after_body = response_body[before_body_end_index..-1].html_safe
|
40
|
+
|
41
|
+
response.body = before_body + clean_script(class_method, arg).html_safe + after_body
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def clean_script(class_method, arg)
|
47
|
+
"<script type='application/javascript'>jQuery(document).ready(function($) {" + render_to_string(js: class_method + arg) + "});</script>"
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "happy_place/controller"
|
2
|
+
|
3
|
+
module HappyPlace
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
initializer "your_gem_name.action_controller" do
|
6
|
+
ActiveSupport.on_load(:action_controller) do
|
7
|
+
puts "Extending #{self} with YourGemsModuleName::Controller"
|
8
|
+
# ActionController::Base gets a method that allows controllers to include the new behavior
|
9
|
+
include HappyPlace::Controller # ActiveSupport::Concern
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/happy_place.rb
ADDED
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: happy_place
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Piccolo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-01 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: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Use javascript in rails in a railsy way.
|
56
|
+
email:
|
57
|
+
- mpiccolo@newleaders.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- happy_place.gemspec
|
68
|
+
- lib/happy_place.rb
|
69
|
+
- lib/happy_place/controller.rb
|
70
|
+
- lib/happy_place/railtie.rb
|
71
|
+
- lib/happy_place/version.rb
|
72
|
+
homepage: ''
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.2.2
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: A happy_place for Rails and JS
|
96
|
+
test_files: []
|