deface 1.5.2 → 1.7.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 +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +15 -16
- data/Appraisals +5 -13
- data/CHANGELOG.markdown +1 -4
- data/README.markdown +1 -1
- data/bin/rails +8 -0
- data/bin/rails-engine +13 -0
- data/bin/rails-sandbox +18 -0
- data/bin/sandbox +40 -0
- data/bin/sandbox-setup +49 -0
- data/deface.gemspec +45 -29
- data/gemfiles/rails_6.0.gemfile +1 -1
- data/gemfiles/{rails_4.2.gemfile → rails_6.1.gemfile} +1 -1
- data/gemfiles/{rails_5.0.gemfile → rails_6_1.gemfile} +1 -1
- data/lib/deface.rb +12 -8
- data/lib/deface/action_view_extensions.rb +57 -83
- data/lib/deface/applicator.rb +2 -4
- data/lib/deface/environment.rb +4 -12
- data/lib/deface/errors.rb +5 -0
- data/lib/deface/override.rb +14 -20
- data/lib/deface/railtie.rb +15 -9
- data/lib/deface/template_helper.rb +39 -16
- data/lib/deface/version.rb +9 -0
- data/spec/deface/action_view_template_spec.rb +101 -79
- data/spec/deface/environment_spec.rb +8 -12
- data/spec/deface/override_spec.rb +2 -2
- data/spec/spec_helper.rb +3 -6
- metadata +54 -18
- data/gemfiles/rails_5.1.gemfile +0 -13
- data/init.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7beeaa21dc8761d6d24072002e6c90c5f7e08f283e603b8404e0b4003e68e557
|
4
|
+
data.tar.gz: 35b96c7138f0c3c5309e35d030bdd758d8c5d9f856924805d5004e5925134423
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e21f73d0d80ae1806cfa6e6ec0244f38f281b87c398a0606a12debb566bdd20458627cbfad341df85a8c72b8c7b16d83bdeec3b36cac071112c07612ef60d75
|
7
|
+
data.tar.gz: 2dac481cd10a35a8d3916af3fbaff0f155f9a7ca9828be454a39fa1c9a4f6c25bf8946a05b7274f1df7025476314cea113be50ffd8a948184bd4ca13619c5022
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,27 +1,26 @@
|
|
1
1
|
script: "bundle exec rake"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
- gem install bundler -v '< 2'
|
3
|
+
cache:
|
4
|
+
bundler: true
|
6
5
|
|
7
6
|
rvm:
|
8
|
-
- 2.
|
9
|
-
- 2.
|
10
|
-
- 2.
|
7
|
+
- 2.5.8
|
8
|
+
- 2.6.6
|
9
|
+
- 2.7.2
|
10
|
+
- 3.0.0
|
11
|
+
|
11
12
|
gemfile:
|
12
|
-
- gemfiles/rails_4.2.gemfile
|
13
|
-
- gemfiles/rails_5.0.gemfile
|
14
|
-
- gemfiles/rails_5.1.gemfile
|
15
13
|
- gemfiles/rails_5.2.gemfile
|
16
14
|
- gemfiles/rails_6.0.gemfile
|
17
|
-
|
18
|
-
email:
|
19
|
-
- brian@spreecommerce.com
|
20
|
-
- ryan@spreecommerce.com
|
15
|
+
- gemfiles/rails_6_1.gemfile
|
21
16
|
|
22
17
|
matrix:
|
23
18
|
exclude:
|
24
|
-
- rvm: 2.
|
25
|
-
gemfile: gemfiles/
|
26
|
-
- rvm: 2.
|
19
|
+
- rvm: 2.6.6
|
20
|
+
gemfile: gemfiles/rails_5.2.gemfile
|
21
|
+
- rvm: 2.7.2
|
22
|
+
gemfile: gemfiles/rails_5.2.gemfile
|
23
|
+
- rvm: 3.0.0
|
24
|
+
gemfile: gemfiles/rails_5.2.gemfile
|
25
|
+
- rvm: 3.0.0
|
27
26
|
gemfile: gemfiles/rails_6.0.gemfile
|
data/Appraisals
CHANGED
@@ -1,19 +1,11 @@
|
|
1
|
-
appraise 'rails-4.2' do
|
2
|
-
gem 'rails', '~> 4.2.0'
|
3
|
-
end
|
4
|
-
|
5
|
-
appraise 'rails-5.0' do
|
6
|
-
gem 'rails', '~> 5.0.0'
|
7
|
-
end
|
8
|
-
|
9
|
-
appraise 'rails-5.1' do
|
10
|
-
gem 'rails', '~> 5.1.0'
|
11
|
-
end
|
12
|
-
|
13
1
|
appraise 'rails-5.2' do
|
14
2
|
gem 'rails', '~> 5.2.0'
|
15
3
|
end
|
16
4
|
|
17
5
|
appraise 'rails-6.0' do
|
18
|
-
gem 'rails', '~> 6.0.0
|
6
|
+
gem 'rails', '~> 6.0.0'
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise 'rails-6.1' do
|
10
|
+
gem 'rails', '~> 6.1.0'
|
19
11
|
end
|
data/CHANGELOG.markdown
CHANGED
@@ -1,4 +1 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* [BREAKING CHANGE] ERB blocks are no longer converted into <code erb-loud|erb-silent>, now they are <erb loud|silent> [jhawthorn]
|
4
|
-
* Lots of other changes too numerous to list here in the first changelog entry, will get better going forward :)
|
1
|
+
*See https://github.com/spree/deface/releases*
|
data/README.markdown
CHANGED
@@ -295,7 +295,7 @@ When using the DSL, overrides automatically take their name from the filename of
|
|
295
295
|
even if they are defined in separate engines. If you want to avoid this, you can use the `namespaced` option :
|
296
296
|
|
297
297
|
```erb
|
298
|
-
<!-- insert_bottom 'head' namespaced-->
|
298
|
+
<!-- insert_bottom 'head' namespaced -->
|
299
299
|
```
|
300
300
|
or activate it globally for all DSL overrides in your app's `application.rb` file:
|
301
301
|
|
data/bin/rails
ADDED
data/bin/rails-engine
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
6
|
+
ENGINE_PATH = File.expand_path('../lib/solidus_paypal_commerce_platform/engine', __dir__)
|
7
|
+
|
8
|
+
# Set up gems listed in the Gemfile.
|
9
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
10
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
11
|
+
|
12
|
+
require 'rails/all'
|
13
|
+
require 'rails/engine/commands'
|
data/bin/rails-sandbox
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
app_root = 'sandbox'
|
6
|
+
|
7
|
+
unless File.exist? "#{app_root}/bin/rails"
|
8
|
+
warn 'Creating the sandbox app...'
|
9
|
+
Dir.chdir "#{__dir__}/.." do
|
10
|
+
system "#{__dir__}/sandbox" or begin # rubocop:disable Style/AndOr
|
11
|
+
warn 'Automatic creation of the sandbox app failed'
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Dir.chdir app_root
|
18
|
+
exec 'bin/rails', *ARGV
|
data/bin/sandbox
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
gem_name="$(ruby -rpathname -e"puts Pathname(ARGV.first).join('../..').expand_path.glob('*.gemspec').first.basename('.gemspec')" -- $0)"
|
4
|
+
|
5
|
+
# Stay away from the bundler env of the containing extension.
|
6
|
+
function unbundled {
|
7
|
+
ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@
|
8
|
+
}
|
9
|
+
|
10
|
+
rm -rf ./sandbox
|
11
|
+
unbundled bundle exec rails new sandbox \
|
12
|
+
--skip-bundle \
|
13
|
+
--skip-git \
|
14
|
+
--skip-javascript \
|
15
|
+
--skip-keeps \
|
16
|
+
--skip-rc \
|
17
|
+
--skip-spring \
|
18
|
+
--skip-test \
|
19
|
+
$@
|
20
|
+
|
21
|
+
if [ ! -d "sandbox" ]; then
|
22
|
+
echo 'sandbox rails application failed'
|
23
|
+
exit 1
|
24
|
+
fi
|
25
|
+
|
26
|
+
cd ./sandbox
|
27
|
+
cat <<RUBY >> Gemfile
|
28
|
+
gem '$gem_name', path: '..'
|
29
|
+
RUBY
|
30
|
+
|
31
|
+
unbundled bundle install --gemfile Gemfile
|
32
|
+
|
33
|
+
unbundled bundle exec rake db:drop db:create
|
34
|
+
|
35
|
+
cd .. # Back to the project root.
|
36
|
+
bin/sandbox-setup # Run any custom setup.
|
37
|
+
|
38
|
+
echo
|
39
|
+
echo "🚀 Sandbox app successfully created for $gem_name!"
|
40
|
+
|
data/bin/sandbox-setup
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
extend FileUtils
|
5
|
+
|
6
|
+
system 'bin/rails g scaffold Post title body'
|
7
|
+
system 'bin/rails db:migrate'
|
8
|
+
|
9
|
+
mkdir_p 'sandbox/app/overrides'
|
10
|
+
|
11
|
+
File.write 'sandbox/app/overrides/improved_posts.rb', <<~RUBY
|
12
|
+
Deface::Override.new(
|
13
|
+
virtual_path: "posts/show",
|
14
|
+
name: "sparkling_post_title",
|
15
|
+
replace: 'p:nth-child(2)',
|
16
|
+
text: "<h1>✨<%= @post.title %>✨</h1>"
|
17
|
+
)
|
18
|
+
|
19
|
+
Deface::Override.new(
|
20
|
+
virtual_path: "posts/show",
|
21
|
+
name: "modern_style_post_body",
|
22
|
+
replace: 'p:nth-child(3)',
|
23
|
+
text: "<p style='border:2px gray solid; padding: 1rem;'><%= @post.body %></p>"
|
24
|
+
)
|
25
|
+
|
26
|
+
Deface::Override.new(
|
27
|
+
virtual_path: "posts/index",
|
28
|
+
name: "sparkling_posts_title",
|
29
|
+
replace: 'tr td:first-child',
|
30
|
+
text: "<td>✨<%= post.title %>✨</td>"
|
31
|
+
)
|
32
|
+
|
33
|
+
Deface::Override.new(
|
34
|
+
virtual_path: "posts/index",
|
35
|
+
name: "modern_style_post_body",
|
36
|
+
replace: 'tr td:nth-child(2)',
|
37
|
+
text: "<td style='border:2px gray solid; padding: 1rem;'><%= post.body %></d>"
|
38
|
+
)
|
39
|
+
RUBY
|
40
|
+
|
41
|
+
File.write 'sandbox/config/routes.rb', <<~RUBY
|
42
|
+
Rails.application.routes.draw do
|
43
|
+
resources :posts
|
44
|
+
root to: "posts#index"
|
45
|
+
end
|
46
|
+
RUBY
|
47
|
+
|
48
|
+
system "bin/rails", "runner", "Post.create(title: 'Foo', body: 'Bar '*10)"
|
49
|
+
system "bin/rails", "runner", "Post.create(title: 'Baz', body: 'Boz '*10)"
|
data/deface.gemspec
CHANGED
@@ -1,30 +1,46 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
1
|
+
require_relative 'lib/deface/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "deface"
|
5
|
+
spec.version = Deface::VERSION
|
6
|
+
spec.authors = ["Brian D Quinn"]
|
7
|
+
spec.email = "brian@spreecommerce.com"
|
8
|
+
|
9
|
+
spec.summary = "Deface is a library that allows you to customize ERB, Haml and Slim views in Rails"
|
10
|
+
spec.description = "Deface is a library that allows you to customize ERB, Haml and Slim views in a Rails application without editing the underlying view."
|
11
|
+
spec.homepage = "https://github.com/spree/deface#readme"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
15
|
+
spec.metadata['source_code_uri'] = 'https://github.com/spree/deface'
|
16
|
+
spec.metadata['changelog_uri'] = 'https://github.com/spree/deface/releases'
|
17
|
+
|
18
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
|
23
|
+
|
24
|
+
spec.files = files.grep_v(%r{^(test|spec|features)/})
|
25
|
+
spec.test_files = files.grep(%r{^(test|spec|features)/})
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
spec.rdoc_options = ["--charset=UTF-8"]
|
30
|
+
spec.extra_rdoc_files = ["README.markdown"]
|
31
|
+
|
32
|
+
spec.add_dependency('nokogiri', '>= 1.6')
|
33
|
+
spec.add_dependency('rails', '>= 5.2')
|
34
|
+
spec.add_dependency('rainbow', '>= 2.1.0')
|
35
|
+
spec.add_dependency('polyglot')
|
36
|
+
|
37
|
+
spec.add_development_dependency('appraisal')
|
38
|
+
spec.add_development_dependency('erubis')
|
39
|
+
spec.add_development_dependency('gem-release')
|
40
|
+
spec.add_development_dependency('rspec', '>= 3.1.0')
|
41
|
+
spec.add_development_dependency('haml', ['>= 4.0', '< 6'])
|
42
|
+
spec.add_development_dependency('slim', '~> 3.0')
|
43
|
+
spec.add_development_dependency('simplecov', '>= 0.6.4')
|
44
|
+
spec.add_development_dependency('generator_spec', '~> 0.8')
|
45
|
+
spec.add_development_dependency('pry')
|
30
46
|
end
|
data/gemfiles/rails_6.0.gemfile
CHANGED
data/lib/deface.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "action_view"
|
2
2
|
require "action_controller"
|
3
|
+
require "deface/errors"
|
3
4
|
require "deface/template_helper"
|
4
5
|
require "deface/original_validator"
|
5
6
|
require "deface/applicator"
|
@@ -38,18 +39,21 @@ require "deface/matchers/range"
|
|
38
39
|
require "deface/environment"
|
39
40
|
require "deface/precompiler"
|
40
41
|
|
42
|
+
require "deface/railtie" if defined?(Rails)
|
43
|
+
|
41
44
|
module Deface
|
42
|
-
|
43
|
-
|
45
|
+
@before_rails_6 = ActionView.gem_version < Gem::Version.new('6.0.0')
|
46
|
+
@template_class = @before_rails_6 ? ActionView::CompiledTemplates : ActionDispatch::DebugView
|
47
|
+
|
48
|
+
def self.before_rails_6?
|
49
|
+
@before_rails_6
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.template_class
|
53
|
+
@template_class
|
44
54
|
end
|
45
55
|
|
46
56
|
if defined?(ActiveSupport::Digest)
|
47
57
|
Deface::Digest.digest_class = ActiveSupport::Digest
|
48
58
|
end
|
49
|
-
|
50
|
-
# Exceptions
|
51
|
-
class DefaceError < StandardError; end
|
52
|
-
|
53
|
-
class NotSupportedError < DefaceError; end
|
54
|
-
|
55
59
|
end
|
@@ -1,102 +1,76 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
# force change in handler before continuing to original Rails method
|
12
|
-
# as we've just converted some other template language into ERB!
|
13
|
-
#
|
14
|
-
if [:slim, :haml].include?(syntax) && processed_source != source.to_param
|
15
|
-
handler = ActionView::Template::Handlers::ERB
|
16
|
-
end
|
1
|
+
module Deface::ActionViewExtensions
|
2
|
+
def self.determine_syntax(handler)
|
3
|
+
return unless Rails.application.config.deface.enabled
|
4
|
+
|
5
|
+
if handler.to_s == "Haml::Plugin"
|
6
|
+
:haml
|
7
|
+
elsif handler.class.to_s == "Slim::RailsTemplate"
|
8
|
+
:slim
|
9
|
+
elsif handler.to_s.demodulize == "ERB" || handler.class.to_s.demodulize == "ERB"
|
10
|
+
:erb
|
17
11
|
else
|
18
|
-
|
12
|
+
nil
|
19
13
|
end
|
20
|
-
|
21
|
-
initialize_without_deface(processed_source, identifier, handler, details)
|
22
14
|
end
|
23
15
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
16
|
+
module DefacedTemplate
|
17
|
+
def encode!
|
18
|
+
return super unless Rails.application.config.deface.enabled
|
19
|
+
|
20
|
+
# Before Rails 6 encode! returns nil
|
21
|
+
source = Deface.before_rails_6? ? (super; @source) : super
|
22
|
+
|
23
|
+
if (syntax = Deface::ActionViewExtensions.determine_syntax(@handler))
|
24
|
+
# Modify the existing string instead of returning a copy
|
25
|
+
source.replace Deface::Override.apply(
|
26
|
+
source, {
|
27
|
+
locals: @locals,
|
28
|
+
format: @format,
|
29
|
+
variant: @variant,
|
30
|
+
virtual_path: @virtual_path,
|
31
|
+
},
|
32
|
+
true,
|
33
|
+
syntax
|
34
|
+
)
|
35
|
+
@handler = ActionView::Template::Handlers::ERB
|
36
|
+
end
|
38
37
|
|
39
|
-
|
40
|
-
@compiled = false
|
41
|
-
@source = refresh(view).source
|
38
|
+
source
|
42
39
|
end
|
43
|
-
render_without_deface(view, locals, buffer, &block)
|
44
|
-
end
|
45
40
|
|
46
|
-
|
41
|
+
private
|
47
42
|
|
48
|
-
|
43
|
+
def compile!(view)
|
44
|
+
return super unless Rails.application.config.deface.enabled
|
49
45
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
def method_name
|
54
|
-
deface_hash = Deface::Override.digest(:virtual_path => @virtual_path)
|
46
|
+
@compile_mutex.synchronize do
|
47
|
+
current_deface_hash = Deface::Override.digest(virtual_path: @virtual_path)
|
48
|
+
@deface_hash = current_deface_hash if @deface_hash.nil?
|
55
49
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
50
|
+
if @deface_hash != current_deface_hash
|
51
|
+
@compiled = nil
|
52
|
+
@deface_hash = current_deface_hash
|
53
|
+
end
|
54
|
+
end
|
61
55
|
|
62
|
-
|
63
|
-
syntax != :unknown
|
56
|
+
super
|
64
57
|
end
|
65
58
|
|
66
|
-
|
67
|
-
|
68
|
-
:haml
|
69
|
-
elsif handler.class.to_s == "Slim::RailsTemplate"
|
70
|
-
:slim
|
71
|
-
elsif handler.to_s.demodulize == "ERB" || handler.class.to_s.demodulize == "ERB"
|
72
|
-
:erb
|
73
|
-
else
|
74
|
-
:unknown
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
59
|
+
ActionView::Template.prepend self
|
60
|
+
end
|
78
61
|
|
79
|
-
# Rails 6 fix
|
80
|
-
#
|
81
|
-
# https://github.com/rails/rails/commit/
|
82
|
-
|
83
|
-
|
62
|
+
# Rails 6 fix.
|
63
|
+
#
|
64
|
+
# https://github.com/rails/rails/commit/ec5c946138f63dc975341d6521587adc74f6b441
|
65
|
+
# https://github.com/rails/rails/commit/ccfa01c36e79013881ffdb7ebe397cec733d15b2#diff-dfb6e0314ad9639bab460ea64871aa47R27
|
66
|
+
module ErubiHandlerFix
|
84
67
|
def initialize(input, properties = {})
|
85
|
-
@
|
86
|
-
|
87
|
-
# Dup properties so that we don't modify argument
|
88
|
-
properties = Hash[properties]
|
89
|
-
properties[:preamble] = "@output_buffer = output_buffer || ActionView::OutputBuffer.new;"
|
90
|
-
properties[:postamble] = "@output_buffer.to_s"
|
91
|
-
properties[:bufvar] = "@output_buffer"
|
92
|
-
properties[:escapefunc] = ""
|
93
|
-
|
68
|
+
properties[:preamble] = "@output_buffer = output_buffer || ActionView::OutputBuffer.new;"
|
94
69
|
super
|
95
70
|
end
|
96
|
-
end
|
97
|
-
end
|
98
71
|
|
99
|
-
#
|
100
|
-
|
101
|
-
|
72
|
+
# We use include to place the module between the class' call to super and the
|
73
|
+
# actual execution within Erubi::Engine.
|
74
|
+
ActionView::Template::Handlers::ERB::Erubi.include self unless Deface.before_rails_6?
|
75
|
+
end
|
102
76
|
end
|