jb 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ffc5acc53f7bb862bfca14507e1fece84d5445d5
4
+ data.tar.gz: 302de13ca7cf90bac12c54d2d9e8dc5fad269fa9
5
+ SHA512:
6
+ metadata.gz: fb23a6af7e5c6075b4f9c79abaa9e2aab1220605b890fd2b1cb3c9875b2d2ee8b3c0c91a27f4bbe2066421c386be6c6640b39cbdd6f1c86a8bb4fe433ef5a410
7
+ data.tar.gz: 4eaec5469d4e4784691fc75af058b7a197d62b0379e2b228e023eafff69cac288d9bf89e2ffa10fb158df4929731362c64a12a5597b99bb85d4ec8a7c7cbe526
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /test/dummy_app/log/*
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jb.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Akira Matsuda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # Jb
2
+
3
+ A simpler and faster Jbuilder alternative.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'jb'
12
+ ```
13
+
14
+ And bundle.
15
+
16
+
17
+ ## Usage
18
+
19
+ Write a template that contains a Ruby code that returns a Ruby Hash / Array object.
20
+ Then the object will be `to_json`ed to a JSON String.
21
+
22
+
23
+ ## Features
24
+
25
+ * No ugly builder syntax
26
+ * No `method_missing` calls
27
+ * `render_partial` with :collection option actually renders the collection (unlike Jbuilder)
28
+
29
+
30
+ ## Contributing
31
+
32
+ Pull requests are welcome on GitHub at https://github.com/amatsuda/jb.
33
+
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jb"
8
+ spec.version = Jb::VERSION
9
+ spec.authors = ["Akira Matsuda"]
10
+ spec.email = ["ronnie@dio.jp"]
11
+
12
+ spec.summary = 'Faster and simpler Jbuilder alternative'
13
+ spec.description = 'Faster and simpler Jbuilder alternative'
14
+ spec.homepage = 'https://github.com/amatsuda/jb'
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency 'test-unit-rails'
25
+ spec.add_development_dependency 'rails'
26
+ spec.add_development_dependency 'capybara'
27
+ end
@@ -0,0 +1,2 @@
1
+ require "jb/version"
2
+ require 'jb/railtie'
@@ -0,0 +1,46 @@
1
+ module Jb
2
+ module PartialRenderer
3
+ module JbTemplateDetector
4
+ # A monkey-patch to inject StrongArray module to Jb partial renderer
5
+ private def find_partial
6
+ template = super
7
+ extend RenderCollectionExtension if template && (template.handler == Jb::Handler)
8
+ template
9
+ end
10
+ end
11
+
12
+ # A horrible monkey-patch to prevent rendered collection from being converted to String
13
+ module StrongArray
14
+ def join(*)
15
+ self
16
+ end
17
+
18
+ def html_safe
19
+ self
20
+ end
21
+ end
22
+
23
+ # A monkey-patch strengthening rendered collection
24
+ module RenderCollectionExtension
25
+ private def collection_with_template
26
+ super.extend StrongArray
27
+ end
28
+
29
+ private def collection_without_template
30
+ super.extend StrongArray
31
+ end
32
+ end
33
+ end
34
+
35
+ # A monkey-patch that converts non-partial result to a JSON String
36
+ module TemplateRenderer
37
+ module JSONizer
38
+ def render_template(template, *)
39
+ template.handler == Jb::Handler ? super.to_json : super
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ ::ActionView::PartialRenderer.prepend ::Jb::PartialRenderer::JbTemplateDetector
46
+ ::ActionView::TemplateRenderer.prepend ::Jb::TemplateRenderer::JSONizer
@@ -0,0 +1,10 @@
1
+ module Jb
2
+ class Handler
3
+ class_attribute :default_format
4
+ self.default_format = :json
5
+
6
+ def self.call(template)
7
+ template.source
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module Jb
2
+ class Railtie < ::Rails::Railtie
3
+ initializer 'jb' do
4
+ ActiveSupport.on_load :action_view do
5
+ require 'jb/action_view_monkeys'
6
+ require 'jb/handler'
7
+ ::ActionView::Template.register_template_handler :jb, Jb::Handler
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Jb
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Akira Matsuda
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: capybara
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Faster and simpler Jbuilder alternative
84
+ email:
85
+ - ronnie@dio.jp
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - jb.gemspec
99
+ - lib/jb.rb
100
+ - lib/jb/action_view_monkeys.rb
101
+ - lib/jb/handler.rb
102
+ - lib/jb/railtie.rb
103
+ - lib/jb/version.rb
104
+ homepage: https://github.com/amatsuda/jb
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.5.1
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Faster and simpler Jbuilder alternative
128
+ test_files: []