deface 1.4.0 → 1.6.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 +1 -0
- data/.travis.yml +15 -16
- data/Appraisals +5 -13
- data/CHANGELOG.markdown +1 -4
- data/README.markdown +3 -3
- 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 +24 -0
- data/deface.gemspec +44 -29
- data/gemfiles/rails_6.0.gemfile +1 -1
- data/gemfiles/{rails_4.2.gemfile → rails_6_1.gemfile} +1 -1
- data/lib/deface.rb +12 -8
- data/lib/deface/action_view_extensions.rb +52 -56
- data/lib/deface/applicator.rb +2 -2
- data/lib/deface/environment.rb +4 -12
- data/lib/deface/errors.rb +5 -0
- data/lib/deface/haml_converter.rb +1 -0
- data/lib/deface/override.rb +14 -13
- data/lib/deface/railtie.rb +15 -9
- data/lib/deface/version.rb +5 -0
- data/spec/deface/action_view_template_spec.rb +121 -70
- data/spec/deface/environment_spec.rb +8 -12
- data/spec/deface/haml_converter_spec.rb +16 -6
- data/spec/deface/override_spec.rb +55 -19
- data/spec/spec_helper.rb +12 -5
- metadata +39 -18
- data/gemfiles/rails_5.0.gemfile +0 -13
- 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: e130d9b889669220392d0fa6fe04ba7cd39604bf8b12edff68308b89d6f3f5f6
|
4
|
+
data.tar.gz: 997c7d4cc5d95a5a5168e70c9da588a9c56b7b67a404b0e4ffaf0410a06426b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 800d393fb3a99206dd0b7922e094458b806e114ab244c8229d37a392affa0faec9455caa85fdba554ece13c95c70064fc663a1644c41cb1b48d693aa35293a56
|
7
|
+
data.tar.gz: 713aaca8fa816ba00f9d66ac8b39596b4818099aff3aa533aa2301d56f1ccd6a15b650477b5621ca669a45b6c949b8f1699fbad4b1a7f339bc7e9ae32f460a8d
|
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
@@ -1,6 +1,6 @@
|
|
1
1
|
<p style="float:right;">
|
2
2
|
<a href="http://secure.travis-ci.org/spree/deface">
|
3
|
-
<img src="https://secure.travis-ci.org/spree/deface.
|
3
|
+
<img src="https://secure.travis-ci.org/spree/deface.svg?branch=master">
|
4
4
|
</a>
|
5
5
|
</p>
|
6
6
|
|
@@ -116,7 +116,7 @@ You should save your overrides in the ````app/overrides````, normally one overri
|
|
116
116
|
* <tt>:sequence</tt> - Used to order the application of an override for a specific virtual path, helpful when an override depends on another override being applied first, supports:
|
117
117
|
* <tt>:sequence => n</tt> - where n is a positive or negative integer (lower numbers get applied first, default 100).
|
118
118
|
* <tt>:sequence => {:before => "*override_name*"}</tt> - where "*override_name*" is the name of an override defined for the
|
119
|
-
same
|
119
|
+
same virtual_path, the current override will be appplied before
|
120
120
|
the named override passed.
|
121
121
|
* <tt>:sequence => {:after => "*override_name*"}</tt> - the current override will be applied after the named override passed.
|
122
122
|
|
@@ -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,24 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
bin/rails g scaffold Post title body
|
4
|
+
bin/rails db:migrate
|
5
|
+
|
6
|
+
mkdir sandbox/app/overrides
|
7
|
+
|
8
|
+
echo <<RUBY >> sandbox/app/overrides/sparkling_title.rb
|
9
|
+
Deface::Override.new(
|
10
|
+
virtual_path: "posts/show",
|
11
|
+
name: "sparkling_title",
|
12
|
+
replace: 'p:nth-child(2)',
|
13
|
+
text: "<h1>✨<%= @post.title %>✨</h1>"
|
14
|
+
)
|
15
|
+
|
16
|
+
Deface::Override.new(
|
17
|
+
virtual_path: "posts/show",
|
18
|
+
name: "sparkling_body",
|
19
|
+
replace: 'p:nth-child(3)',
|
20
|
+
text: "<p style='border:2px gray solid; padding: 1rem;'><%= @post.body %></p>"
|
21
|
+
)
|
22
|
+
RUBY
|
23
|
+
|
24
|
+
bin/rails runner "Post.create(title: 'Foo', body: 'Bar '*10)"
|
data/deface.gemspec
CHANGED
@@ -1,30 +1,45 @@
|
|
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('rspec', '>= 3.1.0')
|
40
|
+
spec.add_development_dependency('haml', ['>= 4.0', '< 6'])
|
41
|
+
spec.add_development_dependency('slim', '~> 3.0')
|
42
|
+
spec.add_development_dependency('simplecov', '>= 0.6.4')
|
43
|
+
spec.add_development_dependency('generator_spec', '~> 0.8')
|
44
|
+
spec.add_development_dependency('pry')
|
30
45
|
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,49 +1,50 @@
|
|
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
|
-
|
16
|
+
module DefacedTemplate
|
17
|
+
def initialize(source, identifier, handler, details)
|
18
|
+
syntax = Deface::ActionViewExtensions.determine_syntax(handler)
|
25
19
|
|
26
|
-
|
27
|
-
|
28
|
-
#
|
29
|
-
def render(view, locals, buffer=nil, &block)
|
20
|
+
if syntax
|
21
|
+
processed_source = Deface::Override.apply(source.to_param, details, true, syntax)
|
30
22
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
23
|
+
# force change in handler before continuing to original Rails method
|
24
|
+
# as we've just converted some other template language into ERB!
|
25
|
+
#
|
26
|
+
if [:slim, :haml].include?(syntax) && processed_source != source.to_param
|
27
|
+
handler = ActionView::Template::Handlers::ERB
|
28
|
+
end
|
29
|
+
else
|
30
|
+
processed_source = source.to_param
|
31
|
+
end
|
36
32
|
|
37
|
-
|
38
|
-
@compiled = false
|
39
|
-
@source = refresh(view).source
|
33
|
+
super(processed_source, identifier, handler, **details)
|
40
34
|
end
|
41
|
-
render_without_deface(view, locals, buffer, &block)
|
42
|
-
end
|
43
35
|
|
44
|
-
|
36
|
+
# refresh view to get source again if
|
37
|
+
# view needs to be recompiled
|
38
|
+
#
|
39
|
+
def render(view, locals, buffer=nil, &block)
|
40
|
+
mod = view.is_a?(Deface.template_class) ? Deface.template_class : view.singleton_class
|
45
41
|
|
46
|
-
|
42
|
+
if @compiled && !mod.instance_methods.include?(method_name.to_sym)
|
43
|
+
@compiled = false
|
44
|
+
@source = refresh(view).source
|
45
|
+
end
|
46
|
+
super(view, locals, buffer, &block)
|
47
|
+
end
|
47
48
|
|
48
49
|
# inject deface hash into compiled view method name
|
49
50
|
# used to determine if recompilation is needed
|
@@ -52,29 +53,24 @@ ActionView::Template.class_eval do
|
|
52
53
|
deface_hash = Deface::Override.digest(:virtual_path => @virtual_path)
|
53
54
|
|
54
55
|
#we digest the whole method name as if it gets too long there's problems
|
55
|
-
"_#{Deface::Digest.hexdigest("#{deface_hash}_#{
|
56
|
+
"_#{Deface::Digest.hexdigest("#{deface_hash}_#{super}")}"
|
56
57
|
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
def should_be_defaced?(syntax)
|
61
|
-
syntax != :unknown
|
62
|
-
end
|
59
|
+
ActionView::Template.prepend self
|
60
|
+
end
|
63
61
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
:unknown
|
73
|
-
end
|
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
|
67
|
+
def initialize(input, properties = {})
|
68
|
+
properties[:preamble] = "@output_buffer = output_buffer || ActionView::OutputBuffer.new;"
|
69
|
+
super
|
74
70
|
end
|
75
|
-
end
|
76
71
|
|
77
|
-
#
|
78
|
-
|
79
|
-
|
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
|
80
76
|
end
|