embed_view 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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +83 -0
- data/Rakefile +27 -0
- data/lib/embed_view.rb +5 -0
- data/lib/embed_view/railtie.rb +42 -0
- data/lib/embed_view/version.rb +3 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4cdcb883310d969dd741bd97e1267794458abaa0edb076f39d9abcf009c12d38
|
4
|
+
data.tar.gz: 35433eafab8095a8901540418c43eb94448177d262e04f31ab28e3aa3f5925d5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6b3d14b410e684ff53dfa445c961acc844d6e714e282c231e7fa2ba745687dc05ca5876f117e30618922d075cf8093d9b636d62b42637e40a39fa8e86579b65b
|
7
|
+
data.tar.gz: a94009231249f1037f8eae51a69a103e8940cd5c90d7271e6b901c579216a846ac6d9c4d3913767a430d29429b25cc0e311a602d0bb323e5a0fe68a4ac6490cc
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2019 Igor Kasyanchuk
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# EmbedView
|
2
|
+
|
3
|
+
Improve application performance by 5-20% (depending on your views and layouts) without major code changes.
|
4
|
+
|
5
|
+
Rails have slow rendering, expecially when you have view and many partials included inside.
|
6
|
+
|
7
|
+
This gem simply embeds views into another views. Works similar to partials, but instead of rendering main view, partials - it's creates a bigger view with content from partials and renders all together.
|
8
|
+
|
9
|
+
So if you have a pretty stable app, rarely changed ERB views(_header, _footer, _ga, _etc...) you can embed them in main view/layout and render together.
|
10
|
+
|
11
|
+
Such small tweak could give 5-20% boost for performance.
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Currently works only with ERB templates.
|
16
|
+
|
17
|
+
Instead of:
|
18
|
+
|
19
|
+
```
|
20
|
+
<%= render '/shared/header' %>
|
21
|
+
```
|
22
|
+
|
23
|
+
just write:
|
24
|
+
|
25
|
+
```
|
26
|
+
<%= embed_view "../shared/_header.html.erb" %>
|
27
|
+
```
|
28
|
+
|
29
|
+
Please note that this is not a typical helper. This is just a meta tag which will be replaced with content from file.
|
30
|
+
|
31
|
+
There are no familiar "locals", "collection", etc things from "partial".
|
32
|
+
|
33
|
+
During development just follow the rule that content from embedded file is inside this file. So all variables available before `embed_view` will be available in inserted file.
|
34
|
+
|
35
|
+
## Installation
|
36
|
+
Add this line to your application's Gemfile:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
gem 'embed_view'
|
40
|
+
```
|
41
|
+
|
42
|
+
And then execute:
|
43
|
+
```bash
|
44
|
+
$ bundle
|
45
|
+
```
|
46
|
+
|
47
|
+
Or install it yourself as:
|
48
|
+
```bash
|
49
|
+
$ gem install embed_view
|
50
|
+
```
|
51
|
+
|
52
|
+
## Known issues
|
53
|
+
|
54
|
+
- if you have an issue in code in embedded file you won't see correct line with error
|
55
|
+
- not tested with older Rails (only with Rails 5.2)
|
56
|
+
|
57
|
+
## TODO
|
58
|
+
|
59
|
+
- better readme with many samples
|
60
|
+
- SLIM support
|
61
|
+
- HAML support
|
62
|
+
- verify how it works with AJAX requests
|
63
|
+
- support older Rails
|
64
|
+
- show line with error in code if crash in ERB
|
65
|
+
- check regexp in code if it's good and fast
|
66
|
+
- think about better logging
|
67
|
+
- other file types support
|
68
|
+
- absolute path (using Rails.root)
|
69
|
+
- more tests (check that content from partials was rendered)
|
70
|
+
- travis.ci
|
71
|
+
- compare numbers(benchmark), visualize in readme
|
72
|
+
- mention in readme links to 2 stagings + source code on heroku
|
73
|
+
- reame in samples apps with link to heroku
|
74
|
+
|
75
|
+
## Benchmarking
|
76
|
+
|
77
|
+
`wrk -t2 -c2 -d10s http://localhost:3000`
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
Contribution directions go here.
|
81
|
+
|
82
|
+
## License
|
83
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
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 = 'EmbedView'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << 'test'
|
23
|
+
t.pattern = 'test/**/*_test.rb'
|
24
|
+
t.verbose = false
|
25
|
+
end
|
26
|
+
|
27
|
+
task default: :test
|
data/lib/embed_view.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module InlineERB
|
2
|
+
module ClassMethods
|
3
|
+
SNIPPET_RE = Regexp.new("<%=.*embed_view.*(\"|\')(.*)(\"|\').*%>").freeze
|
4
|
+
|
5
|
+
def new(*args, &block)
|
6
|
+
source = args[0]
|
7
|
+
identifier = args[1]
|
8
|
+
while (matches = source.scan(SNIPPET_RE)).any? do
|
9
|
+
#puts matches.inspect
|
10
|
+
#puts "-----------------------------------------#{matches.size}--"
|
11
|
+
matches.each do |(a, b, c)|
|
12
|
+
path = File.expand_path(File.join(File.dirname(identifier), b.strip))
|
13
|
+
Rails.logger.debug " embed_view: #{b.strip}"
|
14
|
+
source.gsub!(Regexp.new("<%=.*embed_view.*#{a}#{b}#{c}.*%>"), File.binread(path))
|
15
|
+
identifier = path
|
16
|
+
end
|
17
|
+
end
|
18
|
+
#binding.pry
|
19
|
+
# puts source
|
20
|
+
# puts "--------------------------"
|
21
|
+
# puts "--------------------------"
|
22
|
+
# puts "--------------------------"
|
23
|
+
args[0] = source
|
24
|
+
super(*args, &block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def included(klass)
|
30
|
+
klass.extend(ClassMethods)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
module EmbedView
|
37
|
+
class Railtie < ::Rails::Railtie
|
38
|
+
initializer 'embed_view.helpers' do
|
39
|
+
ActionView::Template.send :include, InlineERB
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embed_view
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Igor Kasyanchuk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-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: 5.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.0.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: '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: minitest-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: minitest-rails-capybara
|
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: Embed partial inline into your views to increase performance of rendering.
|
84
|
+
email:
|
85
|
+
- igorkasyanchuk@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- MIT-LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- lib/embed_view.rb
|
94
|
+
- lib/embed_view/railtie.rb
|
95
|
+
- lib/embed_view/version.rb
|
96
|
+
homepage: http://github.com/igorkasyanchuk/embed_view
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubygems_version: 3.0.2
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Embed partial inline into your views to increase performance of rendering.
|
119
|
+
test_files: []
|