deface 1.5.2 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 040fb8885174112590762a0220dfeb4c1597ff6f4f54804be959d60a9eb80924
4
- data.tar.gz: f87d8e95f18c21a1e75b445556723232365a25003bfdce3898a90c0889eab52d
3
+ metadata.gz: 7beeaa21dc8761d6d24072002e6c90c5f7e08f283e603b8404e0b4003e68e557
4
+ data.tar.gz: 35b96c7138f0c3c5309e35d030bdd758d8c5d9f856924805d5004e5925134423
5
5
  SHA512:
6
- metadata.gz: 39cab3b39f780056f9c47354f20b868d2409eec007bab49f2b60af96392d34d38d412cd9cee634a64847dcab23552c7a7814b2eb5cebd70534ab380feb7833f8
7
- data.tar.gz: 4d2e948527682681bb53fc8e37aeb7b6f9f71b77f571606ed3e78d59991ae8e7362d6d6319af7f1eb50b0cc52fe279d8bab3daa2f7b34df0b29992a134dae677
6
+ metadata.gz: 6e21f73d0d80ae1806cfa6e6ec0244f38f281b87c398a0606a12debb566bdd20458627cbfad341df85a8c72b8c7b16d83bdeec3b36cac071112c07612ef60d75
7
+ data.tar.gz: 2dac481cd10a35a8d3916af3fbaff0f155f9a7ca9828be454a39fa1c9a4f6c25bf8946a05b7274f1df7025476314cea113be50ffd8a948184bd4ca13619c5022
data/.gitignore CHANGED
@@ -6,3 +6,5 @@ coverage/
6
6
  .bundle/
7
7
  gemfiles/*.lock
8
8
  /.idea
9
+ /sandbox
10
+ *.gem
data/.travis.yml CHANGED
@@ -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
data/CHANGELOG.markdown CHANGED
@@ -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*
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
@@ -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
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
- Gem::Specification.new do |s|
2
- s.name = "deface"
3
- s.version = "1.5.2"
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('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
@@ -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"
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 5.0.0"
5
+ gem "rails", "~> 6.1.0"
6
6
 
7
7
  group :test do
8
8
  gem "test-unit"
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
- 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,102 +1,76 @@
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
25
-
26
- # refresh view to get source again if
27
- # view needs to be recompiled
28
- #
29
- def render(view, locals, buffer=nil, &block)
30
-
31
- if Gem.loaded_specs["rails"].version < Gem::Version.new("6.0.0.beta1") && view.is_a?(ActionView::CompiledTemplates)
32
- mod = ActionView::CompiledTemplates
33
- elsif Gem.loaded_specs["rails"].version >= Gem::Version.new("6.0.0.beta1") && view.is_a?(ActionDispatch::DebugView)
34
- mod = ActionDispatch::DebugView
35
- else
36
- mod = view.singleton_class
37
- end
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
- if @compiled && !mod.instance_methods.map(&:to_s).include?(method_name)
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
- protected
41
+ private
47
42
 
48
- alias_method :method_name_without_deface, :method_name
43
+ def compile!(view)
44
+ return super unless Rails.application.config.deface.enabled
49
45
 
50
- # inject deface hash into compiled view method name
51
- # used to determine if recompilation is needed
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
- #we digest the whole method name as if it gets too long there's problems
57
- "_#{Deface::Digest.hexdigest("#{deface_hash}_#{method_name_without_deface}")}"
58
- end
59
-
60
- private
50
+ if @deface_hash != current_deface_hash
51
+ @compiled = nil
52
+ @deface_hash = current_deface_hash
53
+ end
54
+ end
61
55
 
62
- def should_be_defaced?(syntax)
63
- syntax != :unknown
56
+ super
64
57
  end
65
58
 
66
- def determine_syntax(handler)
67
- if handler.to_s == "Haml::Plugin"
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
- # https://github.com/rails/rails/commit/ec5c946138f63dc975341d6521587adc74f6b441
81
- # https://github.com/rails/rails/commit/ccfa01c36e79013881ffdb7ebe397cec733d15b2#diff-dfb6e0314ad9639bab460ea64871aa47R27
82
- if defined?( ActionView::Template::Handlers::ERB::Erubi)
83
- ActionView::Template::Handlers::ERB::Erubi.class_eval do
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
- @newline_pending = 0
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
- #fix for Rails 3.1 not setting virutal_path anymore (BOO!)
100
- if defined?(ActionView::Resolver::Path)
101
- 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
102
76
  end