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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45c7cd1e4905de8fa0fda34bb4c1bed199d1b7b3544417da3caf6470624150d3
4
- data.tar.gz: 0f9750691bc12ff9b1f140c4b9406f7d8b88148151c664205a9abf734925981d
3
+ metadata.gz: e130d9b889669220392d0fa6fe04ba7cd39604bf8b12edff68308b89d6f3f5f6
4
+ data.tar.gz: 997c7d4cc5d95a5a5168e70c9da588a9c56b7b67a404b0e4ffaf0410a06426b6
5
5
  SHA512:
6
- metadata.gz: ac8f3a409db476df004e1665ae1583f5d6aa8e4a16d2d6a9a562511efc27c902b573f1557abc101566878f8b20013b3d316082d4ad61c5af7ec2229e0d0c8a44
7
- data.tar.gz: 630f4f01132534f6fe7c5807b5615b91a54f9e5f19952a53bf10ab75418bcdf6cb79c82c275291a7d8782ba2623293da9b9bdf777d4d8614919e1e94a15d0ec5
6
+ metadata.gz: 800d393fb3a99206dd0b7922e094458b806e114ab244c8229d37a392affa0faec9455caa85fdba554ece13c95c70064fc663a1644c41cb1b48d693aa35293a56
7
+ data.tar.gz: 713aaca8fa816ba00f9d66ac8b39596b4818099aff3aa533aa2301d56f1ccd6a15b650477b5621ca669a45b6c949b8f1699fbad4b1a7f339bc7e9ae32f460a8d
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ coverage/
6
6
  .bundle/
7
7
  gemfiles/*.lock
8
8
  /.idea
9
+ /sandbox
@@ -1,27 +1,26 @@
1
1
  script: "bundle exec rake"
2
2
 
3
- before_install:
4
- - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
5
- - gem install bundler -v '< 2'
3
+ cache:
4
+ bundler: true
6
5
 
7
6
  rvm:
8
- - 2.3.7
9
- - 2.4.4
10
- - 2.5.1
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
- notifications:
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.3.7
25
- gemfile: gemfiles/rails_6.0.gemfile
26
- - rvm: 2.4.4
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.beta3'
6
+ gem 'rails', '~> 6.0.0'
7
+ end
8
+
9
+ appraise 'rails-6.1' do
10
+ gem 'rails', '~> 6.1.0'
19
11
  end
@@ -1,4 +1 @@
1
- ## 1.0.0.rc4 (2013-09-04)
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*
@@ -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.png?branch=master">
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 virutal_path, the current override will be appplied before
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
 
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if %w[e engine].include? ARGV.first
4
+ ARGV.shift # remove the first argument
5
+ exec "#{__dir__}/rails-engine", *ARGV
6
+ else
7
+ exec "#{__dir__}/rails-sandbox", *ARGV
8
+ end
@@ -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'
@@ -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
@@ -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
+
@@ -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)"
@@ -1,30 +1,45 @@
1
- Gem::Specification.new do |s|
2
- s.name = "deface"
3
- s.version = "1.4.0"
4
-
5
- s.authors = ["Brian D Quinn"]
6
- s.description = "Deface is a library that allows you to customize ERB, Haml and Slim views in a Rails application without editing the underlying view."
7
- s.email = "brian@spreecommerce.com"
8
- s.extra_rdoc_files = [
9
- "README.markdown", "CHANGELOG.markdown"
10
- ]
11
- s.files = `git ls-files`.split("\n")
12
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
- s.homepage = "https://github.com/spree/deface"
14
- s.rdoc_options = ["--charset=UTF-8"]
15
- s.require_paths = ["lib"]
16
- s.summary = "Deface is a library that allows you to customize ERB, Haml and Slim views in Rails"
17
-
18
- s.add_dependency('nokogiri', '>= 1.6')
19
- s.add_dependency('rails', '>= 4.1')
20
- s.add_dependency('rainbow', '>= 2.1.0')
21
- s.add_dependency('polyglot')
22
-
23
- s.add_development_dependency('appraisal')
24
- s.add_development_dependency('erubis')
25
- s.add_development_dependency('rspec', '>= 3.1.0')
26
- s.add_development_dependency('haml', ['>= 4.0', '< 6'])
27
- s.add_development_dependency('slim', '~> 3.0')
28
- s.add_development_dependency('simplecov', '>= 0.6.4')
29
- s.add_development_dependency('generator_spec', '~> 0.8')
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 6.0.0.beta3"
5
+ gem "rails", "~> 6.0.0"
6
6
 
7
7
  group :test do
8
8
  gem "test-unit"
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 4.2.0"
5
+ gem "rails", "~> 6.1.0"
6
6
 
7
7
  group :test do
8
8
  gem "test-unit"
@@ -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
- if defined?(Rails)
43
- require "deface/railtie"
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
- ActionView::Template.class_eval do
2
- alias_method :initialize_without_deface, :initialize
3
-
4
- def initialize(source, identifier, handler, details)
5
- syntax = determine_syntax(handler)
6
-
7
- if Rails.application.config.deface.enabled && should_be_defaced?(syntax)
8
-
9
- processed_source = Deface::Override.apply(source.to_param, details, true, syntax)
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
- processed_source = source.to_param
12
+ nil
19
13
  end
20
-
21
- initialize_without_deface(processed_source, identifier, handler, details)
22
14
  end
23
15
 
24
- alias_method :render_without_deface, :render
16
+ module DefacedTemplate
17
+ def initialize(source, identifier, handler, details)
18
+ syntax = Deface::ActionViewExtensions.determine_syntax(handler)
25
19
 
26
- # refresh view to get source again if
27
- # view needs to be recompiled
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
- if view.is_a?(ActionView::Base)
32
- mod = ActionView::Base
33
- else
34
- mod = view.singleton_class
35
- end
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
- if @compiled && !mod.instance_methods.map(&:to_s).include?(method_name)
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
- protected
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
- alias_method :method_name_without_deface, :method_name
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}_#{method_name_without_deface}")}"
56
+ "_#{Deface::Digest.hexdigest("#{deface_hash}_#{super}")}"
56
57
  end
57
58
 
58
- private
59
-
60
- def should_be_defaced?(syntax)
61
- syntax != :unknown
62
- end
59
+ ActionView::Template.prepend self
60
+ end
63
61
 
64
- def determine_syntax(handler)
65
- if handler.to_s == "Haml::Plugin"
66
- :haml
67
- elsif handler.class.to_s == "Slim::RailsTemplate"
68
- :slim
69
- elsif handler.to_s.demodulize == "ERB" || handler.class.to_s.demodulize == "ERB"
70
- :erb
71
- else
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
- #fix for Rails 3.1 not setting virutal_path anymore (BOO!)
78
- if defined?(ActionView::Resolver::Path)
79
- ActionView::Resolver::Path.class_eval { alias_method :virtual, :to_s }
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