Rails 6 autoloader: prepare liquid tags code (#8707)
* Move liquid patches to lib/liquid * Rename classes properly
This commit is contained in:
parent
16f4d7d46a
commit
7309478420
11 changed files with 30 additions and 86 deletions
|
|
@ -1,4 +1,4 @@
|
|||
class JSFiddleTag < LiquidTagBase
|
||||
class JsFiddleTag < LiquidTagBase
|
||||
PARTIAL = "liquids/jsfiddle".freeze
|
||||
OPTION_REGEXP = /\A(js|html|css|result|,)*\z/.freeze
|
||||
LINK_REGEXP = /\A(http|https):\/\/(jsfiddle\.net)\/[a-zA-Z0-9\-\/]*\z/.freeze
|
||||
|
|
@ -51,4 +51,4 @@ class JSFiddleTag < LiquidTagBase
|
|||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_tag("jsfiddle", JSFiddleTag)
|
||||
Liquid::Template.register_tag("jsfiddle", JsFiddleTag)
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
module StandardFilters
|
||||
def append(_input)
|
||||
raise StandardError, "Liquid#append filter is disabled"
|
||||
end
|
||||
|
||||
def concat(_input)
|
||||
raise StandardError, "Liquid#concat filter is disabled"
|
||||
end
|
||||
|
||||
def compact(_input)
|
||||
raise StandardError, "Liquid#compact filter is disabled"
|
||||
end
|
||||
|
||||
def first(_input)
|
||||
raise StandardError, "Liquid#first filter is disabled"
|
||||
end
|
||||
|
||||
def join(_input)
|
||||
raise StandardError, "Liquid#join filter is disabled"
|
||||
end
|
||||
|
||||
def last(_input)
|
||||
raise StandardError, "Liquid#last filter is disabled"
|
||||
end
|
||||
|
||||
def map(_input, _property)
|
||||
raise StandardError, "Liquid#map filter is disabled"
|
||||
end
|
||||
|
||||
def prepend(_input, _string)
|
||||
raise StandardError, "Liquid#prepend filter is disabled"
|
||||
end
|
||||
|
||||
def remove(_input)
|
||||
raise StandardError, "Liquid#remove filter is disabled"
|
||||
end
|
||||
|
||||
def remove_first(_input)
|
||||
raise StandardError, "Liquid#remove_first filter is disabled"
|
||||
end
|
||||
|
||||
def reverse(_input)
|
||||
raise StandardError, "Liquid#reverse filter is disabled"
|
||||
end
|
||||
|
||||
def replace(_input)
|
||||
raise StandardError, "Liquid#replace filter is disabled"
|
||||
end
|
||||
|
||||
def replace_first(_input)
|
||||
raise StandardError, "Liquid#replace_first filter is disabled"
|
||||
end
|
||||
|
||||
def slice(_input)
|
||||
raise StandardError, "Liquid#slice filter is disabled"
|
||||
end
|
||||
|
||||
def split(_input)
|
||||
raise StandardError, "Liquid#split filter is disabled"
|
||||
end
|
||||
|
||||
def truncate(_input)
|
||||
raise StandardError, "Liquid#truncate filter is disabled"
|
||||
end
|
||||
|
||||
def truncatewords(_input)
|
||||
raise StandardError, "Liquid#truncatewords filter is disabled"
|
||||
end
|
||||
|
||||
def uniq(_input, _property)
|
||||
raise StandardError, "Liquid#uniq filter is disabled"
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_filter(StandardFilters)
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
module UrlDecodeFilter
|
||||
def url_decode(input)
|
||||
input
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_filter(UrlDecodeFilter)
|
||||
|
|
@ -1,3 +1,9 @@
|
|||
# TODO: [rhymes] [Rails 6] explicitly requiring dependencies in `classic` mode.
|
||||
# Will move over to `zeitwerk` in a future PR
|
||||
Dir.glob(Rails.root.join("lib/liquid/*.rb")).sort.each do |filename|
|
||||
require_dependency filename
|
||||
end
|
||||
|
||||
# Our custom Liquid tags are registered to Liquid::Template at the bottom of
|
||||
# each files. Each Liquid tags will need to be loaded/required before the main
|
||||
# Liquid gem is evoked, hence the need for the fix below.
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
# Patches Liquid::Raw to change `FullTokenPossiblyInvalid` regexp
|
||||
# see https://github.com/Shopify/liquid/blob/master/lib/liquid/tags/raw.rb
|
||||
|
||||
module Liquid
|
||||
class Raw < Block
|
||||
remove_const(:FullTokenPossiblyInvalid) if defined?(FullTokenPossiblyInvalid)
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
# Disables regular Liquid::Variables like {{ user.name }}
|
||||
# see https://github.com/Shopify/liquid/blob/master/lib/liquid/variable.rb
|
||||
module Liquid
|
||||
class Variable
|
||||
def initialize(_markup, _parse_context)
|
||||
8
spec/lib/liquid/raw_spec.rb
Normal file
8
spec/lib/liquid/raw_spec.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe Liquid::Raw do
|
||||
it "uses the correct regexp for invalid tokens" do
|
||||
expected_regexp = /\A(.*)#{Liquid::TagStart}\s*(\w+)\s*#{Liquid::TagEnd}\z/om
|
||||
expect(described_class::FullTokenPossiblyInvalid).to eq(expected_regexp)
|
||||
end
|
||||
end
|
||||
7
spec/lib/liquid/variable_spec.rb
Normal file
7
spec/lib/liquid/variable_spec.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe Liquid::Variable do
|
||||
it "does not allow instantiation" do
|
||||
expect { described_class.new("", nil) }.to raise_error(StandardError, /variables are disabled/)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe JSFiddleTag, type: :liquid_tag do
|
||||
RSpec.describe JsFiddleTag, type: :liquid_tag do
|
||||
describe "#link" do
|
||||
let(:jsfiddle_link) { "http://jsfiddle.net/link2twenty/v2kx9jcd" }
|
||||
let(:jsfiddle_link_with_custom_tabs) { "http://jsfiddle.net/link2twenty/v2kx9jcd result,html,css" }
|
||||
|
|
@ -12,7 +12,7 @@ RSpec.describe JSFiddleTag, type: :liquid_tag do
|
|||
)
|
||||
|
||||
def generate_new_liquid(link)
|
||||
Liquid::Template.register_tag("jsfiddle", JSFiddleTag)
|
||||
Liquid::Template.register_tag("jsfiddle", JsFiddleTag)
|
||||
Liquid::Template.parse("{% jsfiddle #{link} %}")
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue