tagfiles 1.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.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rubocop.yml +17 -0
- data/.rubocop_todo.yml +6 -0
- data/.travis.yml +23 -0
- data/Gemfile +21 -0
- data/Guardfile +23 -0
- data/LICENSE.txt +22 -0
- data/README.md +83 -0
- data/Rakefile +11 -0
- data/examples/Gemfile +3 -0
- data/examples/Gemfile.lock +104 -0
- data/examples/README.md +13 -0
- data/examples/app/views/example/index.html.erb +15 -0
- data/examples/app/views/example/tagfiles/_label.html.erb +1 -0
- data/examples/app/views/layouts/application.html.erb +15 -0
- data/examples/app/views/tagfiles/_box.html.erb +6 -0
- data/examples/config.ru +27 -0
- data/lib/tagfiles.rb +4 -0
- data/lib/tagfiles/engine.rb +14 -0
- data/lib/tagfiles/tagfile.rb +55 -0
- data/lib/tagfiles/version.rb +3 -0
- data/rakelib/rubocop.rake +18 -0
- data/spec/integration/rails_app.rb +28 -0
- data/spec/integration/rails_app/app/views/namespaced/tagfiles/_outer.html.erb +1 -0
- data/spec/integration/rails_app/app/views/namespaced/test/tagfiles/_inner.html.erb +1 -0
- data/spec/integration/rails_app/app/views/tagfiles/_block.html.erb +1 -0
- data/spec/integration/rails_app/app/views/tagfiles/_simple.html.erb +1 -0
- data/spec/integration/rails_app/app/views/test/tagfiles/_inner.html.erb +1 -0
- data/spec/integration/rails_spec.rb +132 -0
- data/spec/spec_helper.rb +24 -0
- data/tagfiles.gemspec +24 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 50e4b046fc394ab4e7f626914c6be51d5bdc52b9
|
4
|
+
data.tar.gz: d72b5c5166a426f63d49e3ee7b82b34d4e56870c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3900d40e45d7f1759d0cb030ea71ef34957ff3b9baf52fe100bf1fa853336a143757adbcc360a316cc16e7f19fe701654c1a06c511b55aa02ec91ead6c876fc9
|
7
|
+
data.tar.gz: 94293336566945dc55b317db43d5859cce98d2c7333bdc6ac1e118e5546b1d4f9597d24c747e01ddbd07f278f6d1cb865d8b8b22013b184545a801f98f49cc59
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Generated by `rubocop --auto-gen-config`
|
2
|
+
inherit_from: .rubocop_todo.yml
|
3
|
+
|
4
|
+
Lint/HandleExceptions:
|
5
|
+
Exclude:
|
6
|
+
- rakelib/*.rake
|
7
|
+
|
8
|
+
Style/Documentation:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Style/StringLiterals:
|
12
|
+
EnforcedStyle: double_quotes
|
13
|
+
|
14
|
+
Style/RegexpLiteral:
|
15
|
+
Exclude:
|
16
|
+
- tagfiles.gemspec
|
17
|
+
- Guardfile
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2015-03-18 09:45:04 +0100 using RuboCop version 0.29.1.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
data/.travis.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
4
|
+
bundler_args: --without tools
|
5
|
+
rvm:
|
6
|
+
- 2.1
|
7
|
+
matrix:
|
8
|
+
fast_finish: true
|
9
|
+
env:
|
10
|
+
global:
|
11
|
+
- CODECLIMATE_REPO_TOKEN=86c70d1103da065167764882ffb5d184647e2ade2929005a812bea267672cd7e
|
12
|
+
matrix:
|
13
|
+
- RAILS_VERSION='~> 4.2.0'
|
14
|
+
- RAILS_VERSION='~> 4.1.0'
|
15
|
+
- RAILS_VERSION='~> 4.0.0'
|
16
|
+
- RAILS_VERSION='~> 3.2.0'
|
17
|
+
notifications:
|
18
|
+
webhooks:
|
19
|
+
urls:
|
20
|
+
- https://webhooks.gitter.im/e/c6efc69df9417bda7808
|
21
|
+
on_success: change
|
22
|
+
on_failure: always
|
23
|
+
on_start: false
|
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in tagfiles.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :tools do
|
7
|
+
gem "rubocop"
|
8
|
+
gem "guard"
|
9
|
+
gem "guard-minitest"
|
10
|
+
gem "guard-rubocop"
|
11
|
+
end
|
12
|
+
|
13
|
+
rails_version = ENV.fetch("RAILS_VERSION", ">= 0")
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem "rails", rails_version
|
17
|
+
end
|
18
|
+
|
19
|
+
if ENV["CODECLIMATE_REPO_TOKEN"]
|
20
|
+
gem "codeclimate-test-reporter", group: :test, require: nil
|
21
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
group :red_green_refactor, halt_on_fail: true do
|
2
|
+
guard :minitest, cmd: "rake", all_on_start: true do
|
3
|
+
# run all specs if Gemfile.lock is modified
|
4
|
+
watch("Gemfile.lock") { "spec" }
|
5
|
+
|
6
|
+
# run all specs if any library code is modified
|
7
|
+
watch(%r{\Alib/.+\.rb\z}) { "spec" }
|
8
|
+
|
9
|
+
# run all specs if supporting files are modified
|
10
|
+
watch("spec/spec_helper.rb") { "spec" }
|
11
|
+
watch(%r{\Aspec/(?:lib|support|shared|integration)/.+\.rb\z}) { "spec" }
|
12
|
+
watch(%r{\Aspec/.+/views}) { "spec" }
|
13
|
+
|
14
|
+
# run a spec if it is modified
|
15
|
+
watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
|
16
|
+
end
|
17
|
+
|
18
|
+
guard :rubocop do
|
19
|
+
# run rubocop on modified file
|
20
|
+
watch(%r{\Alib/.+\.rb\z})
|
21
|
+
watch(%r{\Aspec/.+\.rb\z})
|
22
|
+
end
|
23
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Peter Suschlik
|
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,83 @@
|
|
1
|
+
[github]: https://github.com/neopoly/tagfiles
|
2
|
+
[doc]: http://rubydoc.info/github/neopoly/tagfiles/master/file/README.md
|
3
|
+
[gem]: https://rubygems.org/gems/tagfiles
|
4
|
+
[gem-badge]: https://img.shields.io/gem/v/tagfiles.svg
|
5
|
+
[travis]: https://travis-ci.org/neopoly/tagfiles
|
6
|
+
[travis-badge]: https://img.shields.io/travis/neopoly/tagfiles.svg?branch=master
|
7
|
+
[codeclimate]: https://codeclimate.com/github/neopoly/tagfiles
|
8
|
+
[codeclimate-climate-badge]: https://img.shields.io/codeclimate/github/neopoly/tagfiles.svg
|
9
|
+
[codeclimate-coverage-badge]: https://codeclimate.com/github/neopoly/tagfiles/badges/coverage.svg
|
10
|
+
[inchpages]: https://inch-ci.org/github/neopoly/tagfiles
|
11
|
+
[inchpages-badge]: https://inch-ci.org/github/neopoly/tagfiles.svg?branch=master&style=flat
|
12
|
+
|
13
|
+
# Tagfiles
|
14
|
+
|
15
|
+
[![Travis][travis-badge]][travis]
|
16
|
+
[![Gem Version][gem-badge]][gem]
|
17
|
+
[![Code Climate][codeclimate-climate-badge]][codeclimate]
|
18
|
+
[![Test Coverage][codeclimate-coverage-badge]][codeclimate]
|
19
|
+
[![Inline docs][inchpages-badge]][inchpages]
|
20
|
+
|
21
|
+
[Gem][gem] |
|
22
|
+
[Source][github] |
|
23
|
+
[Documentation][doc]
|
24
|
+
|
25
|
+
Tagfiles provides the `tagfile` helper for Rails.
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
Add this line to your application's Gemfile:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
gem 'tagfiles'
|
33
|
+
```
|
34
|
+
|
35
|
+
And then execute:
|
36
|
+
|
37
|
+
$ bundle
|
38
|
+
|
39
|
+
## Basic Usage
|
40
|
+
|
41
|
+
Tagfile: `app/views/tagfiles/_box.html.haml`
|
42
|
+
|
43
|
+
```haml
|
44
|
+
.box
|
45
|
+
%h2= title
|
46
|
+
%p= yield
|
47
|
+
```
|
48
|
+
|
49
|
+
HAML file using `box` tagfile: `app/views/admin/page/index.html.haml`
|
50
|
+
|
51
|
+
```haml
|
52
|
+
= tf :box, title: "Box title"
|
53
|
+
Some box content
|
54
|
+
```
|
55
|
+
|
56
|
+
See [examples/](https://github.com/neopoly/tagfiles/tree/master/examples) and [specs](https://github.com/neopoly/tagfiles/blob/master/spec/integration/rails_spec.rb) for more examples.
|
57
|
+
|
58
|
+
## Lookup order
|
59
|
+
|
60
|
+
Rendering the `box` tagfile from the example above will trigger with following lookups:
|
61
|
+
|
62
|
+
* `app/views/admin/page/tagfiles/_box.html.erb`
|
63
|
+
* `app/views/admin/tagfiles/_box.html.erb`
|
64
|
+
* `app/views/tagfiles/_box.html.erb`
|
65
|
+
|
66
|
+
## Rails support
|
67
|
+
|
68
|
+
Following Rails versions are supported:
|
69
|
+
|
70
|
+
* 4.2
|
71
|
+
* 4.1
|
72
|
+
* 4.0
|
73
|
+
* 3.2
|
74
|
+
|
75
|
+
Feel free to test earlier Rails versions. Feedback is welcome!
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
1. [Fork it](https://github.com/neopoly/tagfiles/fork)
|
80
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
81
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
82
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
83
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/examples/Gemfile
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionmailer (4.2.0)
|
5
|
+
actionpack (= 4.2.0)
|
6
|
+
actionview (= 4.2.0)
|
7
|
+
activejob (= 4.2.0)
|
8
|
+
mail (~> 2.5, >= 2.5.4)
|
9
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
10
|
+
actionpack (4.2.0)
|
11
|
+
actionview (= 4.2.0)
|
12
|
+
activesupport (= 4.2.0)
|
13
|
+
rack (~> 1.6.0)
|
14
|
+
rack-test (~> 0.6.2)
|
15
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
16
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
17
|
+
actionview (4.2.0)
|
18
|
+
activesupport (= 4.2.0)
|
19
|
+
builder (~> 3.1)
|
20
|
+
erubis (~> 2.7.0)
|
21
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
22
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
23
|
+
activejob (4.2.0)
|
24
|
+
activesupport (= 4.2.0)
|
25
|
+
globalid (>= 0.3.0)
|
26
|
+
activemodel (4.2.0)
|
27
|
+
activesupport (= 4.2.0)
|
28
|
+
builder (~> 3.1)
|
29
|
+
activerecord (4.2.0)
|
30
|
+
activemodel (= 4.2.0)
|
31
|
+
activesupport (= 4.2.0)
|
32
|
+
arel (~> 6.0)
|
33
|
+
activesupport (4.2.0)
|
34
|
+
i18n (~> 0.7)
|
35
|
+
json (~> 1.7, >= 1.7.7)
|
36
|
+
minitest (~> 5.1)
|
37
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
38
|
+
tzinfo (~> 1.1)
|
39
|
+
arel (6.0.0)
|
40
|
+
builder (3.2.2)
|
41
|
+
erubis (2.7.0)
|
42
|
+
globalid (0.3.3)
|
43
|
+
activesupport (>= 4.1.0)
|
44
|
+
hike (1.2.3)
|
45
|
+
i18n (0.7.0)
|
46
|
+
json (1.8.2)
|
47
|
+
loofah (2.0.1)
|
48
|
+
nokogiri (>= 1.5.9)
|
49
|
+
mail (2.6.3)
|
50
|
+
mime-types (>= 1.16, < 3)
|
51
|
+
mime-types (2.4.3)
|
52
|
+
mini_portile (0.6.2)
|
53
|
+
minitest (5.5.1)
|
54
|
+
multi_json (1.11.0)
|
55
|
+
nokogiri (1.6.6.2)
|
56
|
+
mini_portile (~> 0.6.0)
|
57
|
+
rack (1.6.0)
|
58
|
+
rack-test (0.6.3)
|
59
|
+
rack (>= 1.0)
|
60
|
+
rails (4.2.0)
|
61
|
+
actionmailer (= 4.2.0)
|
62
|
+
actionpack (= 4.2.0)
|
63
|
+
actionview (= 4.2.0)
|
64
|
+
activejob (= 4.2.0)
|
65
|
+
activemodel (= 4.2.0)
|
66
|
+
activerecord (= 4.2.0)
|
67
|
+
activesupport (= 4.2.0)
|
68
|
+
bundler (>= 1.3.0, < 2.0)
|
69
|
+
railties (= 4.2.0)
|
70
|
+
sprockets-rails
|
71
|
+
rails-deprecated_sanitizer (1.0.3)
|
72
|
+
activesupport (>= 4.2.0.alpha)
|
73
|
+
rails-dom-testing (1.0.6)
|
74
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
75
|
+
nokogiri (~> 1.6.0)
|
76
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
77
|
+
rails-html-sanitizer (1.0.2)
|
78
|
+
loofah (~> 2.0)
|
79
|
+
railties (4.2.0)
|
80
|
+
actionpack (= 4.2.0)
|
81
|
+
activesupport (= 4.2.0)
|
82
|
+
rake (>= 0.8.7)
|
83
|
+
thor (>= 0.18.1, < 2.0)
|
84
|
+
rake (10.4.2)
|
85
|
+
sprockets (2.12.3)
|
86
|
+
hike (~> 1.2)
|
87
|
+
multi_json (~> 1.0)
|
88
|
+
rack (~> 1.0)
|
89
|
+
tilt (~> 1.1, != 1.3.0)
|
90
|
+
sprockets-rails (2.2.4)
|
91
|
+
actionpack (>= 3.0)
|
92
|
+
activesupport (>= 3.0)
|
93
|
+
sprockets (>= 2.8, < 4.0)
|
94
|
+
thor (0.19.1)
|
95
|
+
thread_safe (0.3.5)
|
96
|
+
tilt (1.4.1)
|
97
|
+
tzinfo (1.2.2)
|
98
|
+
thread_safe (~> 0.1)
|
99
|
+
|
100
|
+
PLATFORMS
|
101
|
+
ruby
|
102
|
+
|
103
|
+
DEPENDENCIES
|
104
|
+
rails
|
data/examples/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Example app
|
2
|
+
|
3
|
+
This example app demonstrates a basic usage of this `tagfiles` gem.
|
4
|
+
|
5
|
+
## Run
|
6
|
+
|
7
|
+
$ bundle
|
8
|
+
$ rackup
|
9
|
+
$ open http://localhost:9292
|
10
|
+
|
11
|
+
## Browse
|
12
|
+
|
13
|
+
The tagfiles are located in `app/views/tagfiles` and `app/views/example/tagfiles`.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%= tf :box, title: "Plain box" do %>
|
2
|
+
Box content
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<%= tf :box, title: "Nested box" do %>
|
6
|
+
<%= tf :box, title: "Level 2" do %>
|
7
|
+
Nested content
|
8
|
+
<% end %>
|
9
|
+
<% end %>
|
10
|
+
|
11
|
+
<%= tf :box, title: "No content" %>
|
12
|
+
|
13
|
+
<h3>
|
14
|
+
<%= tf :label, value: "controller specific tagfile" %>
|
15
|
+
</h3>
|
@@ -0,0 +1 @@
|
|
1
|
+
<span class="label label-default"><%= value %></span>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
|
5
|
+
</head>
|
6
|
+
<body>
|
7
|
+
<div class="page-header">
|
8
|
+
<h1>Tagfiles example</h1>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<div class="content">
|
12
|
+
<%= yield %>
|
13
|
+
</div>
|
14
|
+
</body>
|
15
|
+
</html>
|
data/examples/config.ru
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "rails"
|
2
|
+
require "action_controller/railtie"
|
3
|
+
|
4
|
+
$LOAD_PATH << "../lib"
|
5
|
+
require "tagfiles"
|
6
|
+
|
7
|
+
class ExampleApp < Rails::Application
|
8
|
+
routes.append do
|
9
|
+
get "/" => "example#index"
|
10
|
+
end
|
11
|
+
|
12
|
+
config.eager_load = false
|
13
|
+
|
14
|
+
config.secret_key_base = "a" * 30
|
15
|
+
config.secret_token = "b" * 30
|
16
|
+
end
|
17
|
+
|
18
|
+
class ExampleController < ActionController::Base
|
19
|
+
layout "application"
|
20
|
+
|
21
|
+
def index
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
ExampleApp.initialize!
|
26
|
+
|
27
|
+
run ExampleApp
|
data/lib/tagfiles.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Tagfiles
|
2
|
+
# Easy tagfile integration into Rails
|
3
|
+
class Engine < Rails::Engine
|
4
|
+
initializer "tagfiles" do
|
5
|
+
ActiveSupport.on_load :action_controller do
|
6
|
+
include Tagfiles::Tagfile
|
7
|
+
end
|
8
|
+
|
9
|
+
ActiveSupport.on_load :action_view do
|
10
|
+
include Tagfiles::Tagfile
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# Tagfiles provides the `tagfile` helper for Rails.
|
2
|
+
module Tagfiles
|
3
|
+
# Tagfile implementation
|
4
|
+
module Tagfile
|
5
|
+
# Renders a +layout+ when called with a block or +partial+ otherwise.
|
6
|
+
#
|
7
|
+
# @param name [String] name of the used tagfile
|
8
|
+
# @param locals [Hash] optional locals passed to the tagfile
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# app/views/admin/page/index.html.erb:
|
12
|
+
#
|
13
|
+
# <%= tagfile :box, title: 23 do %>
|
14
|
+
# Box content
|
15
|
+
# <% end %>
|
16
|
+
#
|
17
|
+
# app/views/tagfiles/_box.html.erb
|
18
|
+
#
|
19
|
+
# <div class="box">
|
20
|
+
# <h2><%= title %></h2>
|
21
|
+
# <p><%= yield %></p>
|
22
|
+
# </div>
|
23
|
+
#
|
24
|
+
# Following partial lookups will be performed:
|
25
|
+
# * app/views/admin/page/tagfiles/_box.html.erb
|
26
|
+
# * app/views/admin/tagfiles/_box.html.erb
|
27
|
+
# * app/views/tagfiles/_box.html.erb
|
28
|
+
def tagfile(name, locals = {}, &block)
|
29
|
+
prefix = lookup_tagfile_prefix(controller.controller_path || "", name)
|
30
|
+
|
31
|
+
if block
|
32
|
+
render layout: "#{prefix}/#{name}", locals: locals, &block
|
33
|
+
else
|
34
|
+
render partial: "#{prefix}/#{name}", locals: locals
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
alias_method :tf, :tagfile
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
TAGFILES_DIR = "tagfiles"
|
43
|
+
|
44
|
+
def lookup_tagfile_prefix(controller_path, name)
|
45
|
+
parts = controller_path.split("/")
|
46
|
+
|
47
|
+
loop do
|
48
|
+
prefix = (parts + [TAGFILES_DIR]).join("/")
|
49
|
+
break prefix if controller.template_exists?(name, [prefix], true)
|
50
|
+
parts.pop
|
51
|
+
break TAGFILES_DIR if parts.empty?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
begin
|
2
|
+
require "rubocop/rake_task"
|
3
|
+
|
4
|
+
Rake::Task[:default].enhance [:rubocop]
|
5
|
+
|
6
|
+
RuboCop::RakeTask.new do |task|
|
7
|
+
task.options << "--display-cop-names"
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :rubocop do
|
11
|
+
desc "Generate a configuration file acting as a TODO list."
|
12
|
+
task :auto_gen_config do
|
13
|
+
exec "bundle exec rubocop --auto-gen-config"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
rescue LoadError
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "rails"
|
2
|
+
require "action_controller/railtie"
|
3
|
+
|
4
|
+
# TODO: Find out how to remove this line below
|
5
|
+
require "tagfiles/engine"
|
6
|
+
|
7
|
+
class RailsApp < Rails::Application
|
8
|
+
routes.append do
|
9
|
+
get "/:controller/:action"
|
10
|
+
namespace :namespaced do
|
11
|
+
get "/:action" => "test"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
config.logger = nil
|
16
|
+
config.log_level = :warn
|
17
|
+
|
18
|
+
# Enable cache classes. Production style.
|
19
|
+
config.cache_classes = true
|
20
|
+
config.eager_load = true
|
21
|
+
|
22
|
+
config.secret_key_base = "a" * 30
|
23
|
+
config.secret_token = "b" * 30
|
24
|
+
|
25
|
+
config.root = File.expand_path("./rails_app", File.dirname(__FILE__))
|
26
|
+
end
|
27
|
+
|
28
|
+
RailsApp.initialize!
|
@@ -0,0 +1 @@
|
|
1
|
+
outer
|
@@ -0,0 +1 @@
|
|
1
|
+
most inner
|
@@ -0,0 +1 @@
|
|
1
|
+
block[<%= raw local_assigns.inspect %>](<%= yield %>)
|
@@ -0,0 +1 @@
|
|
1
|
+
simple[<%= raw local_assigns.inspect %>](<%= yield %>)
|
@@ -0,0 +1 @@
|
|
1
|
+
inner
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
ENV["RACK_ENV"] = "test"
|
4
|
+
|
5
|
+
require_relative "rails_app"
|
6
|
+
|
7
|
+
class TestController < ActionController::Base
|
8
|
+
def simple_alias
|
9
|
+
render inline: "<%= tagfile :simple %>"
|
10
|
+
end
|
11
|
+
|
12
|
+
def simple
|
13
|
+
render inline: "<%= tf :simple %>"
|
14
|
+
end
|
15
|
+
|
16
|
+
def simple_with_params
|
17
|
+
render inline: "<%= tf :simple, param: params[:param] %>"
|
18
|
+
end
|
19
|
+
|
20
|
+
def block
|
21
|
+
render inline: "<%= tf :simple do %>content<% end %>"
|
22
|
+
end
|
23
|
+
|
24
|
+
def block_with_params
|
25
|
+
render inline: "<%= tf :simple, param: params[:param] do %>content<% end %>"
|
26
|
+
end
|
27
|
+
|
28
|
+
def inner
|
29
|
+
render inline: "<%= tf :inner %>"
|
30
|
+
end
|
31
|
+
|
32
|
+
def missing
|
33
|
+
render inline: "<%= tf :missing %>"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module Namespaced
|
38
|
+
class TestController < ActionController::Base
|
39
|
+
def inner
|
40
|
+
render inline: "<%= tf :inner %>"
|
41
|
+
end
|
42
|
+
|
43
|
+
def outer
|
44
|
+
render inline: "<%= tf :outer %>"
|
45
|
+
end
|
46
|
+
|
47
|
+
def simple
|
48
|
+
render inline: "<%= tf :simple %>"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe RailsApp do
|
54
|
+
describe "w/o block" do
|
55
|
+
it "renders partial from tagfiles/ w/o params aliased" do
|
56
|
+
get "/test/simple_alias"
|
57
|
+
assert_body %(simple[{:simple=>nil}]())
|
58
|
+
end
|
59
|
+
|
60
|
+
it "renders partial from tagfiles/ w/o params" do
|
61
|
+
get "/test/simple"
|
62
|
+
assert_body %(simple[{:simple=>nil}]())
|
63
|
+
end
|
64
|
+
|
65
|
+
it "renders partial from tagfiles/ with params" do
|
66
|
+
get "/test/simple_with_params", param: "foo"
|
67
|
+
assert_body %(simple[{:param=>"foo", :simple=>nil}]())
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "with block" do
|
72
|
+
it "renders layout from tagfiles/ w/o params" do
|
73
|
+
get "/test/block"
|
74
|
+
assert_body %(simple[{:simple=>nil}](content))
|
75
|
+
end
|
76
|
+
|
77
|
+
it "renders layout from tagfiles/ with params" do
|
78
|
+
get "/test/block_with_params", param: "foo"
|
79
|
+
assert_body %(simple[{:param=>"foo", :simple=>nil}](content))
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "inner tagfile" do
|
84
|
+
it "prefers inner tagfile in test/tagfiles/" do
|
85
|
+
get "/test/inner"
|
86
|
+
assert_body %(inner)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "renders most inner tagfile in namespaced/test/tagfiles" do
|
90
|
+
get "/namespaced/test/inner"
|
91
|
+
assert_body %(most inner)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "renders outer tagfile in namespaced/tagfiles" do
|
95
|
+
get "/namespaced/test/outer"
|
96
|
+
assert_body %(outer)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "renders most outer simple tagfile" do
|
100
|
+
get "/namespaced/test/simple"
|
101
|
+
assert_body %(simple[{:simple=>nil}]())
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "missing template" do
|
106
|
+
it "error for missing template" do
|
107
|
+
get "/test/missing"
|
108
|
+
assert_equal 500, last_response.status
|
109
|
+
assert_body ""
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "anonymous controllers" do
|
114
|
+
let(:anon_controller) do
|
115
|
+
Class.new(ActionController::Base) do
|
116
|
+
def anon
|
117
|
+
render inline: "<%= tf :simple %>"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
it "renders tagfile even w/o a name" do
|
123
|
+
controller = anon_controller
|
124
|
+
RailsApp.routes.draw do
|
125
|
+
get "/anon", to: controller.action(:anon)
|
126
|
+
end
|
127
|
+
|
128
|
+
get "/anon"
|
129
|
+
assert_body %(simple[{:simple=>nil}]())
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler.require
|
3
|
+
|
4
|
+
if ENV["CODECLIMATE_REPO_TOKEN"]
|
5
|
+
require "codeclimate-test-reporter"
|
6
|
+
CodeClimate::TestReporter.start
|
7
|
+
end
|
8
|
+
|
9
|
+
require "minitest/autorun"
|
10
|
+
require "rack/test"
|
11
|
+
|
12
|
+
class IntegrationSpec < Minitest::Spec
|
13
|
+
include Rack::Test::Methods
|
14
|
+
|
15
|
+
def app
|
16
|
+
RailsApp
|
17
|
+
end
|
18
|
+
|
19
|
+
def assert_body(expected)
|
20
|
+
assert_equal expected, last_response.body.strip
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
MiniTest::Spec.register_spec_type("RailsApp", IntegrationSpec)
|
data/tagfiles.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "tagfiles/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tagfiles"
|
8
|
+
spec.version = Tagfiles::VERSION
|
9
|
+
spec.authors = ["Peter Suschlik"]
|
10
|
+
spec.email = ["ps@neopoly.de"]
|
11
|
+
spec.summary = "Provides the tagfile helper for Rails"
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/neopoly/tagfiles"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "minitest"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tagfiles
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Suschlik
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-19 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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: minitest
|
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: Provides the tagfile helper for Rails
|
56
|
+
email:
|
57
|
+
- ps@neopoly.de
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rubocop.yml"
|
64
|
+
- ".rubocop_todo.yml"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- Guardfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- examples/Gemfile
|
72
|
+
- examples/Gemfile.lock
|
73
|
+
- examples/README.md
|
74
|
+
- examples/app/views/example/index.html.erb
|
75
|
+
- examples/app/views/example/tagfiles/_label.html.erb
|
76
|
+
- examples/app/views/layouts/application.html.erb
|
77
|
+
- examples/app/views/tagfiles/_box.html.erb
|
78
|
+
- examples/config.ru
|
79
|
+
- lib/tagfiles.rb
|
80
|
+
- lib/tagfiles/engine.rb
|
81
|
+
- lib/tagfiles/tagfile.rb
|
82
|
+
- lib/tagfiles/version.rb
|
83
|
+
- rakelib/rubocop.rake
|
84
|
+
- spec/integration/rails_app.rb
|
85
|
+
- spec/integration/rails_app/app/views/namespaced/tagfiles/_outer.html.erb
|
86
|
+
- spec/integration/rails_app/app/views/namespaced/test/tagfiles/_inner.html.erb
|
87
|
+
- spec/integration/rails_app/app/views/tagfiles/_block.html.erb
|
88
|
+
- spec/integration/rails_app/app/views/tagfiles/_simple.html.erb
|
89
|
+
- spec/integration/rails_app/app/views/test/tagfiles/_inner.html.erb
|
90
|
+
- spec/integration/rails_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
- tagfiles.gemspec
|
93
|
+
homepage: https://github.com/neopoly/tagfiles
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.2.2
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Provides the tagfile helper for Rails
|
117
|
+
test_files:
|
118
|
+
- spec/integration/rails_app.rb
|
119
|
+
- spec/integration/rails_app/app/views/namespaced/tagfiles/_outer.html.erb
|
120
|
+
- spec/integration/rails_app/app/views/namespaced/test/tagfiles/_inner.html.erb
|
121
|
+
- spec/integration/rails_app/app/views/tagfiles/_block.html.erb
|
122
|
+
- spec/integration/rails_app/app/views/tagfiles/_simple.html.erb
|
123
|
+
- spec/integration/rails_app/app/views/test/tagfiles/_inner.html.erb
|
124
|
+
- spec/integration/rails_spec.rb
|
125
|
+
- spec/spec_helper.rb
|