jubako 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e59d567d99960b86a2ae3556086704dd5e4ed15b
4
+ data.tar.gz: ed89d7e1fb91c72b3cf2588ea564cb43208501b2
5
+ SHA512:
6
+ metadata.gz: 96b41a49c8a52e25f17a4d531b1553cb25ea210b6250c348c7679b4447cf1afc86d736adc4dcf7ed9d87f522f0b088e00ac784ea7af32b6667737c600ae70d0c
7
+ data.tar.gz: 09eae93539e9dd7c418c4143d8fb5e79217f67c9916c52c01b4004358beeb181f4fae4f1f4c755441e4293471013a8e449506fa1e2d5075a64cb8b63e25517be
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Yuki Hattori
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,93 @@
1
+ # Jubako
2
+
3
+ ### ***[WARNING] Jubako is under developing. Current version has not test. Don't use this gem!***
4
+
5
+ Jubako gives multi-level layout inheritance in Rails view, like [Jade's template inheritance](http://jade-lang.com/reference/inheritance/).
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your Rails application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'jubako'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install jubako
23
+
24
+
25
+ ## Usage
26
+
27
+ These usage are using [Slim](https://github.com/slim-template/slim).
28
+
29
+ ### Layout (Template) inheritance
30
+
31
+ Jubako defines `extends` method in view helper. When you call `extends` with layout path (in anywhere of view), it will render with using specified layout.
32
+
33
+ Have you specified any layout before rendering? It applies after Jubako inheritances.
34
+
35
+ #### app/views/top/index.slim
36
+
37
+ ```slim
38
+ - extends 'layouts/base_template'
39
+
40
+ - block :body
41
+ h1 Top#index
42
+ p Find me in app/views/top/index.slim
43
+ ```
44
+
45
+ #### app/views/layouts/base_template.slim
46
+
47
+ ```slim
48
+ - block :title
49
+ title Base template's title
50
+
51
+ = block :body
52
+ ```
53
+
54
+ #### app/views/layouts/application.slim
55
+
56
+ ```slim
57
+ doctype html
58
+ html
59
+ head
60
+ = block :title
61
+ body
62
+ = yield
63
+ ```
64
+
65
+ #### Output
66
+
67
+ ```html
68
+ <!DOCTYPE html>
69
+ <html>
70
+ <head>
71
+ <title>Base template's title</title>
72
+ </head>
73
+ <body>
74
+ <h1>
75
+ Top#index
76
+ </h1>
77
+ <p>
78
+ Find me in app/views/top/index.slim
79
+ </p>
80
+ </body>
81
+ </html>
82
+ ```
83
+
84
+ ## Contributing
85
+
86
+ Jubako is under developing by [Yuki Hattori](https://github.com/yhatt/).
87
+
88
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/yhatt/jubako](https://github.com/yhatt/jubako).
89
+
90
+
91
+ ## License
92
+
93
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Jubako'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
@@ -0,0 +1 @@
1
+ <%= jubako_renderer(jubako_original_layout, local_assigns) { yield } %>
@@ -0,0 +1,10 @@
1
+ require "jubako/engine"
2
+ require "jubako/renderer"
3
+ require "jubako/template_renderer"
4
+ require "jubako/helpers/extends"
5
+ require "jubako/helpers/block"
6
+
7
+ ActionView::TemplateRenderer.send(:include, Jubako::TemplateRenderer)
8
+ ActionView::Base.send(:include, Jubako::Renderer)
9
+ ActionView::Base.send(:include, Jubako::Helpers::Extends)
10
+ ActionView::Base.send(:include, Jubako::Helpers::Block)
@@ -0,0 +1,5 @@
1
+ module Jubako
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Jubako
4
+ end
5
+ end
@@ -0,0 +1,64 @@
1
+ module Jubako::Helpers
2
+ module Block
3
+ def block(body = nil, append: nil, prepend: nil, &block)
4
+ name = body || append || prepend
5
+
6
+ if content_for?(body_name(name))
7
+ return render_block(name)
8
+ else
9
+ content = block_given? ? capture(&block) : ''
10
+ ret = render_block(name, content)
11
+
12
+ if block_given?
13
+ if !body.nil?
14
+ replace_body(name, content)
15
+ elsif !append.nil?
16
+ add_append(name, content)
17
+ elsif !prepend.nil?
18
+ add_prepend(name, content)
19
+ end
20
+ end
21
+
22
+ ret
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def render_block(name, body = nil)
29
+ capture do
30
+ concat content_for(prepend_name(name))
31
+ concat body.nil? ? content_for(body_name(name)) : body
32
+ concat content_for(append_name(name))
33
+ end
34
+ end
35
+
36
+ def body_name(name)
37
+ "jubako_block_body__#{name}"
38
+ end
39
+
40
+ def replace_body(name, body)
41
+ content_for(body_name(name), body, flush: true)
42
+ end
43
+
44
+ def append_name(name)
45
+ "jubako_block_append__#{name}"
46
+ end
47
+
48
+ def add_append(name, body)
49
+ content_for(append_name(name), body)
50
+ end
51
+
52
+ def prepend_name(name)
53
+ "jubako_block_prepend__#{name}"
54
+ end
55
+
56
+ def add_prepend(name, body)
57
+ replaced_body = capture do
58
+ concat body
59
+ concat content_for(prepend_name(name))
60
+ end
61
+ content_for(prepend_name(name), replaced_body, flush: true)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,7 @@
1
+ module Jubako::Helpers
2
+ module Extends
3
+ def extends(layout)
4
+ content_for(:jubako_extend_layout, layout, flush: true)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ module Jubako
2
+ module Renderer
3
+ def jubako_renderer(layout, locals = {})
4
+ extends = content_for(:jubako_extend_layout)
5
+ layout = layout.call if layout.is_a?(Proc)
6
+ args = { locals: locals }
7
+
8
+ content_for(:jubako_extend_layout, '', flush: true)
9
+
10
+ if layout.nil?
11
+ if extends.nil?
12
+ return yield
13
+ else
14
+ args[:template] = extends
15
+ end
16
+ else
17
+ if extends.nil?
18
+ args[:template] = layout
19
+ else
20
+ args[:template] = extends
21
+ args[:layout] = layout
22
+ end
23
+ end
24
+
25
+ render(args)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ module Jubako
2
+ module TemplateRenderer
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ alias_method_chain :render_template, :jubako
7
+ end
8
+
9
+ def render_template_with_jubako(template, layout_name = nil, locals = nil)
10
+ locals ||= {}
11
+ locals[:jubako_original_layout] = layout_name
12
+
13
+ layout_name = find_layout('layout/jubako', locals.keys)
14
+ render_template_without_jubako(template, layout_name, locals)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Jubako
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jubako
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yuki Hattori
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-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.1.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.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
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
+ description: Jubako gives multi-level layout inheritance in Rails view.
56
+ email:
57
+ - yukihattori1116@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - app/views/layout/jubako.html.erb
66
+ - lib/jubako.rb
67
+ - lib/jubako/engine.rb
68
+ - lib/jubako/helpers/block.rb
69
+ - lib/jubako/helpers/extends.rb
70
+ - lib/jubako/renderer.rb
71
+ - lib/jubako/template_renderer.rb
72
+ - lib/jubako/version.rb
73
+ homepage: https://github.com/yhatt
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.5.1
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Support multi-level layout inheritances in Rails view
97
+ test_files: []