virgo 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/virgo/install/install_generator.rb +20 -0
- data/lib/generators/virgo/migrations/migrations_generator.rb +19 -0
- data/lib/generators/virgo/schedule/schedule_generator.rb +15 -0
- data/lib/generators/virgo/views/views_generator.rb +22 -0
- data/lib/tasks/virgo_tasks.rake +7 -0
- data/lib/virgo.rb +4 -0
- data/lib/virgo/development_mail_interceptor.rb +6 -0
- data/lib/virgo/email_validator.rb +6 -0
- data/lib/virgo/engine.rb +64 -0
- data/lib/virgo/reduce_validator.rb +6 -0
- data/lib/virgo/upload_helpers.rb +89 -0
- data/lib/virgo/version.rb +3 -0
- data/lib/virgo/view_help.rb +3 -0
- data/vendor/gems/shortcode/Appraisals +15 -0
- data/vendor/gems/shortcode/CHANGELOG.md +162 -0
- data/vendor/gems/shortcode/Gemfile +6 -0
- data/vendor/gems/shortcode/Gemfile.lock +168 -0
- data/vendor/gems/shortcode/LICENSE.txt +22 -0
- data/vendor/gems/shortcode/README.md +268 -0
- data/vendor/gems/shortcode/Rakefile +3 -0
- data/vendor/gems/shortcode/gemfiles/rails_3.2.gemfile +8 -0
- data/vendor/gems/shortcode/gemfiles/rails_4.0.gemfile +8 -0
- data/vendor/gems/shortcode/gemfiles/rails_4.1.gemfile +8 -0
- data/vendor/gems/shortcode/gemfiles/rails_4.2.gemfile +8 -0
- data/vendor/gems/shortcode/lib/shortcode.rb +53 -0
- data/vendor/gems/shortcode/lib/shortcode/configuration.rb +36 -0
- data/vendor/gems/shortcode/lib/shortcode/exceptions.rb +9 -0
- data/vendor/gems/shortcode/lib/shortcode/parser.rb +43 -0
- data/vendor/gems/shortcode/lib/shortcode/presenter.rb +49 -0
- data/vendor/gems/shortcode/lib/shortcode/processor.rb +17 -0
- data/vendor/gems/shortcode/lib/shortcode/railtie.rb +3 -0
- data/vendor/gems/shortcode/lib/shortcode/tag.rb +54 -0
- data/vendor/gems/shortcode/lib/shortcode/template_binding.rb +33 -0
- data/vendor/gems/shortcode/lib/shortcode/transformer.rb +17 -0
- data/vendor/gems/shortcode/lib/shortcode/version.rb +3 -0
- data/vendor/gems/shortcode/shortcode.gemspec +30 -0
- data/vendor/gems/shortcode/spec/parser_spec.rb +267 -0
- data/vendor/gems/shortcode/spec/performance_spec.rb +41 -0
- data/vendor/gems/shortcode/spec/presenter_spec.rb +126 -0
- data/vendor/gems/shortcode/spec/rails_helpers_spec.rb +72 -0
- data/vendor/gems/shortcode/spec/shortcode_spec.rb +57 -0
- data/vendor/gems/shortcode/spec/spec_helper.rb +32 -0
- data/vendor/gems/shortcode/spec/support/fixtures.rb +9 -0
- data/vendor/gems/shortcode/spec/support/fixtures/block_with_whitespace.txt +2 -0
- data/vendor/gems/shortcode/spec/support/fixtures/block_with_whitespace_output.html +2 -0
- data/vendor/gems/shortcode/spec/support/fixtures/complex_snippet.txt +13 -0
- data/vendor/gems/shortcode/spec/support/fixtures/complex_snippet_output.html +33 -0
- data/vendor/gems/shortcode/spec/support/fixtures/custom_helper.txt +1 -0
- data/vendor/gems/shortcode/spec/support/fixtures/custom_helper_output.html +1 -0
- data/vendor/gems/shortcode/spec/support/fixtures/full_quote.txt +1 -0
- data/vendor/gems/shortcode/spec/support/fixtures/full_quote_output.html +7 -0
- data/vendor/gems/shortcode/spec/support/fixtures/item.txt +1 -0
- data/vendor/gems/shortcode/spec/support/fixtures/item_presenter_attributes_output.html +4 -0
- data/vendor/gems/shortcode/spec/support/fixtures/item_presenter_output.html +4 -0
- data/vendor/gems/shortcode/spec/support/fixtures/long_text.txt +39 -0
- data/vendor/gems/shortcode/spec/support/fixtures/quote_with_extras.txt +1 -0
- data/vendor/gems/shortcode/spec/support/fixtures/quote_with_extras_output.html +7 -0
- data/vendor/gems/shortcode/spec/support/fixtures/rails_helper.txt +1 -0
- data/vendor/gems/shortcode/spec/support/fixtures/rails_helper_output_erb.html +1 -0
- data/vendor/gems/shortcode/spec/support/fixtures/rails_helper_output_haml.html +1 -0
- data/vendor/gems/shortcode/spec/support/fixtures/rails_helper_output_slim.html +1 -0
- data/vendor/gems/shortcode/spec/support/fixtures/simple_list.txt +5 -0
- data/vendor/gems/shortcode/spec/support/fixtures/simple_list_output.html +15 -0
- data/vendor/gems/shortcode/spec/support/fixtures/simple_quote.txt +1 -0
- data/vendor/gems/shortcode/spec/support/fixtures/simple_quote_output.html +3 -0
- data/vendor/gems/shortcode/spec/support/fixtures/simple_quote_presenter_attributes_output.html +6 -0
- data/vendor/gems/shortcode/spec/support/fixtures/simple_quote_presenter_output.html +6 -0
- data/vendor/gems/shortcode/spec/support/fixtures/timeline_event.txt +1 -0
- data/vendor/gems/shortcode/spec/support/fixtures/timeline_event_output.html +15 -0
- data/vendor/gems/shortcode/spec/support/fixtures/timeline_info.txt +1 -0
- data/vendor/gems/shortcode/spec/support/fixtures/timeline_info_output.html +14 -0
- data/vendor/gems/shortcode/spec/support/fixtures/timeline_person.txt +4 -0
- data/vendor/gems/shortcode/spec/support/fixtures/timeline_person_output.html +23 -0
- data/vendor/gems/shortcode/spec/support/fixtures/without_quotes.txt +1 -0
- data/vendor/gems/shortcode/spec/support/presenters/missing_attributes_presenter.rb +12 -0
- data/vendor/gems/shortcode/spec/support/presenters/missing_content_presenter.rb +12 -0
- data/vendor/gems/shortcode/spec/support/presenters/missing_for_presenter.rb +12 -0
- data/vendor/gems/shortcode/spec/support/presenters/missing_initialize_presenter.rb +12 -0
- data/vendor/gems/shortcode/spec/support/presenters/multiple_presenter.rb +19 -0
- data/vendor/gems/shortcode/spec/support/presenters/my_presenter.rb +19 -0
- data/vendor/gems/shortcode/spec/support/presenters/other_presenter.rb +19 -0
- data/vendor/gems/shortcode/spec/support/templates/erb/collapsible_list.html.erb +3 -0
- data/vendor/gems/shortcode/spec/support/templates/erb/custom_helper.html.erb +1 -0
- data/vendor/gems/shortcode/spec/support/templates/erb/item.html.erb +4 -0
- data/vendor/gems/shortcode/spec/support/templates/erb/quote.html.erb +13 -0
- data/vendor/gems/shortcode/spec/support/templates/erb/rails_helper.html.erb +1 -0
- data/vendor/gems/shortcode/spec/support/templates/erb/timeline_event.html.erb +17 -0
- data/vendor/gems/shortcode/spec/support/templates/erb/timeline_info.html.erb +15 -0
- data/vendor/gems/shortcode/spec/support/templates/erb/timeline_person.html.erb +23 -0
- data/vendor/gems/shortcode/spec/support/templates/haml/quote.html.haml +8 -0
- data/vendor/gems/shortcode/spec/support/templates/haml/rails_helper.html.haml +1 -0
- data/vendor/gems/shortcode/spec/support/templates/slim/quote.html.slim +8 -0
- data/vendor/gems/shortcode/spec/support/templates/slim/rails_helper.html.slim +1 -0
- data/vendor/gems/shortcode/spec/tag_spec.rb +67 -0
- data/vendor/gems/shortcode/spec/template_parsers_spec.rb +46 -0
- data/vendor/gems/shortcode/spec/transformer_spec.rb +122 -0
- metadata +97 -1
@@ -0,0 +1,53 @@
|
|
1
|
+
$:.unshift File.expand_path('..', __FILE__)
|
2
|
+
|
3
|
+
require 'parslet'
|
4
|
+
require 'erb'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'haml'
|
8
|
+
rescue LoadError; end
|
9
|
+
|
10
|
+
begin
|
11
|
+
require 'slim'
|
12
|
+
rescue LoadError; end
|
13
|
+
|
14
|
+
module Shortcode
|
15
|
+
|
16
|
+
class << self
|
17
|
+
attr_writer :configuration
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.process(string, additional_attributes=nil)
|
21
|
+
Shortcode::Processor.new.process string, additional_attributes
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.setup
|
25
|
+
yield configuration
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.register_presenter(*presenters)
|
29
|
+
presenters.each do |presenter|
|
30
|
+
Shortcode::Presenter.register presenter
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def self.configuration
|
37
|
+
@configuration ||= Configuration.new
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
require 'shortcode/version'
|
43
|
+
require 'shortcode/configuration'
|
44
|
+
require 'shortcode/parser'
|
45
|
+
require 'shortcode/presenter'
|
46
|
+
require 'shortcode/processor'
|
47
|
+
require 'shortcode/template_binding'
|
48
|
+
require 'shortcode/transformer'
|
49
|
+
require 'shortcode/tag'
|
50
|
+
require 'shortcode/exceptions'
|
51
|
+
require 'shortcode/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3
|
52
|
+
|
53
|
+
Shortcode.setup {}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Shortcode::Configuration
|
2
|
+
# Sets the template parser to use, supports :erb, :haml, and :slim, default is :haml
|
3
|
+
attr_accessor :template_parser
|
4
|
+
|
5
|
+
# Sets the path to search for template files
|
6
|
+
attr_accessor :template_paths
|
7
|
+
|
8
|
+
# Allows templates to be set from strings rather than read from the filesystem
|
9
|
+
attr_accessor :templates
|
10
|
+
|
11
|
+
# Assigns helper modules to be included in templates
|
12
|
+
attr_accessor :helpers
|
13
|
+
|
14
|
+
# Set the supported block_tags
|
15
|
+
attr_accessor :block_tags
|
16
|
+
|
17
|
+
# Set the supported self_closing_tags
|
18
|
+
attr_accessor :self_closing_tags
|
19
|
+
|
20
|
+
# Set the quotation sign used for attribute values. Defaults to double quote (")
|
21
|
+
attr_accessor :attribute_quote_type
|
22
|
+
|
23
|
+
# Allows quotes around attributes to be omitted. Defaults to false (quotes must be present around the value).
|
24
|
+
attr_accessor :use_attribute_quotes
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
@template_parser = :erb
|
28
|
+
@template_paths = ["app/views/shortcode_templates"]
|
29
|
+
@templates = nil
|
30
|
+
@helpers = []
|
31
|
+
@block_tags = []
|
32
|
+
@self_closing_tags = []
|
33
|
+
@attribute_quote_type = '"'
|
34
|
+
@use_attribute_quotes = true
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Shortcode::Parser < Parslet::Parser
|
2
|
+
|
3
|
+
rule(:block_tag) { match_any_of Shortcode.configuration.block_tags }
|
4
|
+
rule(:self_closing_tag) { match_any_of Shortcode.configuration.self_closing_tags }
|
5
|
+
|
6
|
+
rule(:quotes) { str(Shortcode.configuration.attribute_quote_type) }
|
7
|
+
|
8
|
+
rule(:space) { str(' ').repeat(1) }
|
9
|
+
rule(:space?) { space.maybe }
|
10
|
+
rule(:newline) { (str("\r\n") | str("\n")) >> space? }
|
11
|
+
rule(:newline?) { newline.maybe }
|
12
|
+
rule(:whitespace) { (space | newline).repeat(1) }
|
13
|
+
|
14
|
+
rule(:key) { match('[a-zA-Z0-9\-_]').repeat(1) }
|
15
|
+
|
16
|
+
rule(:value_with_quotes) { quotes >> (quotes.absent? >> any).repeat.as(:value) >> quotes }
|
17
|
+
rule(:value_without_quotes) { quotes.absent? >> ( (str(']') | whitespace).absent? >> any ).repeat.as(:value) }
|
18
|
+
rule(:value) { Shortcode.configuration.use_attribute_quotes ? value_with_quotes : (value_without_quotes | value_with_quotes) }
|
19
|
+
|
20
|
+
rule(:option) { key.as(:key) >> str('=') >> value }
|
21
|
+
rule(:options) { (str(' ') >> option).repeat(1) }
|
22
|
+
rule(:options?) { options.repeat(0, 1) }
|
23
|
+
|
24
|
+
rule(:open) { str('[') >> block_tag.as(:open) >> options?.as(:options) >> str(']') >> newline? }
|
25
|
+
rule(:close) { str('[/') >> block_tag.as(:close) >> str(']') >> newline? }
|
26
|
+
rule(:open_close) { str('[') >> self_closing_tag.as(:open_close) >> options?.as(:options) >> str(']') >> newline? }
|
27
|
+
|
28
|
+
rule(:text) { ((close | block | open_close).absent? >> any).repeat(1).as(:text) }
|
29
|
+
rule(:block) { (open >> (block | text | open_close).repeat.as(:inner) >> close) }
|
30
|
+
|
31
|
+
rule(:body) { (block | text | open_close).repeat.as(:body) }
|
32
|
+
root(:body)
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def match_any_of(tags)
|
37
|
+
return str('') if tags.length < 1
|
38
|
+
tags.map{ |tag| str(tag) }.inject do |tag_chain, tag|
|
39
|
+
tag_chain.send :|, tag
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class Shortcode::Presenter
|
2
|
+
|
3
|
+
class << self
|
4
|
+
attr_writer :presenters
|
5
|
+
|
6
|
+
def presenters
|
7
|
+
@presenters ||= {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def register(presenter)
|
11
|
+
validate presenter
|
12
|
+
[*presenter.for].each { |k| presenters[k.to_sym] = presenter }
|
13
|
+
end
|
14
|
+
|
15
|
+
def validate(presenter)
|
16
|
+
raise ArgumentError, "The presenter must define the class method #for" unless presenter.respond_to?(:for)
|
17
|
+
raise ArgumentError, "The presenter must define an initialize method" unless presenter.private_instance_methods(false).include?(:initialize)
|
18
|
+
%w(content attributes).each do |method|
|
19
|
+
raise ArgumentError, "The presenter must define the method ##{method}" unless presenter.method_defined?(method.to_sym)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(name, attributes, content, additional_attributes)
|
25
|
+
@attributes = attributes
|
26
|
+
@content = content
|
27
|
+
@additional_attributes = additional_attributes
|
28
|
+
initialize_custom_presenter(name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def content
|
32
|
+
@content
|
33
|
+
end
|
34
|
+
|
35
|
+
def attributes
|
36
|
+
@attributes
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def initialize_custom_presenter(name)
|
42
|
+
if Shortcode::Presenter.presenters.has_key? name.to_sym
|
43
|
+
presenter = Shortcode::Presenter.presenters[name.to_sym].new(@attributes, @content, @additional_attributes)
|
44
|
+
@attributes = presenter.attributes
|
45
|
+
@content = presenter.content
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Shortcode::Processor
|
2
|
+
|
3
|
+
def process(string, additional_attributes=nil)
|
4
|
+
transformer.apply parser.parse(string), additional_attributes: additional_attributes
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def parser
|
10
|
+
@parser ||= Shortcode::Parser.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def transformer
|
14
|
+
@transformer ||= Shortcode::Transformer.new
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class Shortcode::Tag
|
2
|
+
|
3
|
+
def initialize(name, attributes=[], content='', additional_attributes=nil)
|
4
|
+
@name = name.downcase
|
5
|
+
@binding = Shortcode::TemplateBinding.new(@name, attributes, content, additional_attributes)
|
6
|
+
end
|
7
|
+
|
8
|
+
def markup
|
9
|
+
return markup_from_config unless Shortcode.configuration.templates.nil?
|
10
|
+
template_files.each do |path|
|
11
|
+
return File.read(path) if File.file? path
|
12
|
+
end
|
13
|
+
raise Shortcode::TemplateNotFound, "Searched in:", template_files
|
14
|
+
end
|
15
|
+
|
16
|
+
def render
|
17
|
+
render_template
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def render_template
|
23
|
+
case Shortcode.configuration.template_parser
|
24
|
+
when :erb
|
25
|
+
ERB.new(markup).result(@binding.get_binding)
|
26
|
+
when :haml
|
27
|
+
Haml::Engine.new(markup, ugly: true).render(@binding)
|
28
|
+
when :slim
|
29
|
+
Slim::Template.new { markup }.render(@binding)
|
30
|
+
else
|
31
|
+
raise Shortcode::TemplateParserNotSupported, Shortcode.configuration.template_parser
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def markup_from_config
|
36
|
+
if Shortcode.configuration.templates.has_key? @name.to_sym
|
37
|
+
Shortcode.configuration.templates[@name.to_sym]
|
38
|
+
else
|
39
|
+
raise Shortcode::TemplateNotFound, "Shortcode.configuration.templates does not contain the key #{@name.to_sym}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def template_files
|
44
|
+
expanded_template_paths.map do |filename|
|
45
|
+
Shortcode.configuration.template_paths.reverse.map do |path|
|
46
|
+
File.join path, filename
|
47
|
+
end
|
48
|
+
end.flatten
|
49
|
+
end
|
50
|
+
|
51
|
+
def expanded_template_paths
|
52
|
+
[ "#{@name}.html.#{Shortcode.configuration.template_parser.to_s}", "#{@name}.#{Shortcode.configuration.template_parser.to_s}" ]
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Shortcode::TemplateBinding
|
2
|
+
|
3
|
+
def initialize(name, attributes=[], content='', additional_attributes=nil)
|
4
|
+
include_helper_modules
|
5
|
+
presenter = Shortcode::Presenter.new name, set_attributes(attributes), content, additional_attributes
|
6
|
+
@name = name
|
7
|
+
@attributes = presenter.attributes
|
8
|
+
@content = presenter.content
|
9
|
+
end
|
10
|
+
|
11
|
+
# Expose private binding() method for use with erb templates
|
12
|
+
def get_binding
|
13
|
+
binding
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def set_attributes(attributes)
|
19
|
+
hash = {}
|
20
|
+
attributes.each { |o| hash[o[:key].to_sym] = o[:value] }
|
21
|
+
hash
|
22
|
+
end
|
23
|
+
|
24
|
+
def include_helper_modules
|
25
|
+
return unless Shortcode.configuration.helpers.any?
|
26
|
+
class << self
|
27
|
+
Shortcode.configuration.helpers.each do |helper|
|
28
|
+
include helper
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Shortcode::Transformer < Parslet::Transform
|
2
|
+
|
3
|
+
rule(text: simple(:text)) { String(text) }
|
4
|
+
rule(
|
5
|
+
open: simple(:name),
|
6
|
+
options: subtree(:options),
|
7
|
+
inner: sequence(:inner),
|
8
|
+
close: simple(:name)
|
9
|
+
) { Shortcode::Tag.new(name.to_s, options, inner.join, additional_attributes).render }
|
10
|
+
rule(
|
11
|
+
open_close: simple(:name),
|
12
|
+
options: subtree(:options)
|
13
|
+
) { Shortcode::Tag.new(name.to_s, options, '', additional_attributes).render }
|
14
|
+
|
15
|
+
rule(body: sequence(:strings)) { strings.join }
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'shortcode/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "shortcode"
|
8
|
+
spec.version = Shortcode::VERSION
|
9
|
+
spec.authors = ["Jamie Dyer"]
|
10
|
+
spec.email = ["jamie@kernowsoul.com"]
|
11
|
+
spec.description = "Gem for parsing wordpress style shortcodes"
|
12
|
+
spec.summary = "Gem for parsing wordpress style shortcodes in ruby projects"
|
13
|
+
spec.homepage = "https://github.com/kernow/shortcode"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "parslet", "1.7.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.4"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
26
|
+
spec.add_development_dependency "coveralls", "~> 0"
|
27
|
+
spec.add_development_dependency "slim", "~> 3.0"
|
28
|
+
spec.add_development_dependency "haml", "~> 4.0"
|
29
|
+
spec.add_development_dependency "rails"
|
30
|
+
end
|
@@ -0,0 +1,267 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'parslet/rig/rspec'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
describe Shortcode::Parser do
|
6
|
+
|
7
|
+
let(:parser) { Shortcode::Parser.new }
|
8
|
+
|
9
|
+
let(:simple_quote) { load_fixture :simple_quote }
|
10
|
+
let(:full_quote) { load_fixture :full_quote }
|
11
|
+
let(:without_quotes) { load_fixture :without_quotes }
|
12
|
+
let(:quote_with_extras) { load_fixture :quote_with_extras }
|
13
|
+
let(:simple_list) { load_fixture :simple_list }
|
14
|
+
let(:timeline_event) { load_fixture :timeline_event }
|
15
|
+
let(:timeline_info) { load_fixture :timeline_info }
|
16
|
+
let(:timeline_person) { load_fixture :timeline_person }
|
17
|
+
let(:complex_snippet) { load_fixture :complex_snippet }
|
18
|
+
|
19
|
+
let(:quotes) { [simple_quote, full_quote, quote_with_extras] }
|
20
|
+
let(:collapsible_lists) { [simple_list] }
|
21
|
+
let(:timelines) { [timeline_event, timeline_info, timeline_person] }
|
22
|
+
|
23
|
+
it "parses quote shortcodes" do
|
24
|
+
quotes.each do |string|
|
25
|
+
expect(parser).to parse(string)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "attribute_quote_type configuration" do
|
30
|
+
|
31
|
+
before do
|
32
|
+
Shortcode.setup do |config|
|
33
|
+
config.attribute_quote_type = "'"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "parses quotes using custom quotations" do
|
38
|
+
quotes.each do |string|
|
39
|
+
# Change double quotes to single quotes in the fixture
|
40
|
+
expect(parser).to parse(string.gsub '"', "'")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
context "use_attribute_quotes configuration" do
|
47
|
+
|
48
|
+
before do
|
49
|
+
Shortcode.setup do |config|
|
50
|
+
config.use_attribute_quotes = false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "parses shortcodes with optional quotes" do
|
55
|
+
expect(parser).to parse(without_quotes)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
it "parses list shortcodes" do
|
61
|
+
collapsible_lists.each do |string|
|
62
|
+
expect(parser).to parse(string)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "parses timeline shortcodes" do
|
67
|
+
timelines.each do |string|
|
68
|
+
expect(parser).to parse(string)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "parses complex nested shortcodes" do
|
73
|
+
expect(parser).to parse(complex_snippet)
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "parsed strings" do
|
77
|
+
|
78
|
+
context "simple_quote" do
|
79
|
+
|
80
|
+
let(:parsed_object) { parser.parse(simple_quote) }
|
81
|
+
|
82
|
+
it "created the expected object" do
|
83
|
+
expect(parsed_object[:body]).to eq([{ open: "quote", options: [], inner: [{ text: "hello" }], close: "quote" }])
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
context "full_quote" do
|
89
|
+
|
90
|
+
let(:parsed_object) { parser.parse(full_quote) }
|
91
|
+
|
92
|
+
it "created the expected object" do
|
93
|
+
expect(parsed_object[:body]).to eq([{
|
94
|
+
open: "quote",
|
95
|
+
options: [
|
96
|
+
{ key: "author", value: "Jamie Dyer" },
|
97
|
+
{ key: "title", value: "King of England" }
|
98
|
+
],
|
99
|
+
inner: [{ text: "A quote" }],
|
100
|
+
close: "quote"
|
101
|
+
}])
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
context "quote_with_extras" do
|
107
|
+
|
108
|
+
let(:parsed_object) { parser.parse(quote_with_extras) }
|
109
|
+
|
110
|
+
it "created the expected object" do
|
111
|
+
expect(parsed_object[:body]).to eq([
|
112
|
+
{ text: "Blah blah " },
|
113
|
+
{
|
114
|
+
open: "quote",
|
115
|
+
options: [
|
116
|
+
{ key: "author", value: "Jamie Dyer" }
|
117
|
+
],
|
118
|
+
inner: [{ text: "A quote" }],
|
119
|
+
close: "quote"
|
120
|
+
},
|
121
|
+
{ text: " <br> blah blah\n" }
|
122
|
+
])
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
context "simple_list" do
|
128
|
+
|
129
|
+
let(:parsed_object) { parser.parse(simple_list) }
|
130
|
+
|
131
|
+
it "created the expected object" do
|
132
|
+
expect(parsed_object[:body]).to eq([{
|
133
|
+
open: "collapsible_list",
|
134
|
+
options: [],
|
135
|
+
inner: [{
|
136
|
+
open: "item",
|
137
|
+
options: [{ key: "title", value: "Example title 1" }],
|
138
|
+
inner: [{ text: "Example content 1" }],
|
139
|
+
close: "item"
|
140
|
+
},
|
141
|
+
{
|
142
|
+
open: "item",
|
143
|
+
options: [{ key: "title", value: "Example title 2" }],
|
144
|
+
inner: [{ text: "Example content 2" }],
|
145
|
+
close: "item"
|
146
|
+
},
|
147
|
+
{
|
148
|
+
open: "item",
|
149
|
+
options: [{ key: "title", value: "Example title 3" }],
|
150
|
+
inner: [{ text: "Example content 3" }],
|
151
|
+
close: "item"
|
152
|
+
}],
|
153
|
+
close: "collapsible_list"
|
154
|
+
}])
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
context "timeline_event" do
|
160
|
+
|
161
|
+
let(:parsed_object) { parser.parse(timeline_event) }
|
162
|
+
|
163
|
+
it "created the expected object" do
|
164
|
+
expect(parsed_object[:body]).to eq([{
|
165
|
+
open_close: "timeline_event",
|
166
|
+
options: [
|
167
|
+
{ key: "date", value: "March 2013" },
|
168
|
+
{ key: "title", value: "a title" },
|
169
|
+
{ key: "link", value: "http://blah.com" }
|
170
|
+
]
|
171
|
+
}])
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
context "timeline_info" do
|
177
|
+
|
178
|
+
let(:parsed_object) { parser.parse(timeline_info) }
|
179
|
+
|
180
|
+
it "created the expected object" do
|
181
|
+
expect(parsed_object[:body]).to eq([{
|
182
|
+
open_close: "timeline_info",
|
183
|
+
options: [
|
184
|
+
{ key: "date", value: "Feb 2013" },
|
185
|
+
{ key: "title", value: "Something amazing" }
|
186
|
+
]
|
187
|
+
}])
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
context "timeline_person" do
|
193
|
+
|
194
|
+
let(:parsed_object) { parser.parse(timeline_person) }
|
195
|
+
|
196
|
+
it "created the expected object" do
|
197
|
+
expect(parsed_object[:body]).to eq([{
|
198
|
+
open: "timeline_person",
|
199
|
+
options: [
|
200
|
+
{ key: "date", value: "Jan 2012" },
|
201
|
+
{ key: "title", value: "A real title" },
|
202
|
+
{ key: "image", value: "/images/person.jpg" },
|
203
|
+
{ key: "name", value: "Sam Smith" },
|
204
|
+
{ key: "position", value: "Presedent" },
|
205
|
+
{ key: "link", value: "http://blah.com" }
|
206
|
+
],
|
207
|
+
inner: [{ text: "A bit of body copy\nwith a newline\n" }],
|
208
|
+
close: "timeline_person"
|
209
|
+
}])
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
context "complex_snippet" do
|
215
|
+
|
216
|
+
let(:parsed_object) { parser.parse(complex_snippet) }
|
217
|
+
|
218
|
+
it "created the expected object" do
|
219
|
+
expect(parsed_object[:body]).to eq([{
|
220
|
+
text: "<h3>A page title</h3>\n<p>Some text</p>\n"},
|
221
|
+
{
|
222
|
+
open: "collapsible_list",
|
223
|
+
options: [],
|
224
|
+
inner: [{
|
225
|
+
open: "item",
|
226
|
+
options: [{ key: "title", value: "Example title 1" }],
|
227
|
+
inner: [{
|
228
|
+
open: "quote",
|
229
|
+
options: [
|
230
|
+
{ key: "author", value: "Jamie Dyer" },
|
231
|
+
{ key: "title", value: "King of England" }
|
232
|
+
],
|
233
|
+
inner: [{ text: "A quote" }],
|
234
|
+
close: "quote"
|
235
|
+
},
|
236
|
+
{ text: "I'm inbetween 2 quotes!\n " },
|
237
|
+
{
|
238
|
+
open: "quote",
|
239
|
+
options: [
|
240
|
+
{ key: "author", value: "Forrest Gump" },
|
241
|
+
{ key: "title", value: "Idiot" }
|
242
|
+
],
|
243
|
+
inner: [{text: "Life is like..."}],
|
244
|
+
close: "quote"
|
245
|
+
}],
|
246
|
+
close: "item"
|
247
|
+
},
|
248
|
+
{
|
249
|
+
open: "item",
|
250
|
+
options: [{ key: "title", value: "Example title 2" }],
|
251
|
+
inner: [{ text: "Example content 2" }],
|
252
|
+
close: "item"
|
253
|
+
},
|
254
|
+
{
|
255
|
+
open: "item",
|
256
|
+
options: [{ key: "title", value: "Example title 3" }],
|
257
|
+
inner: [{ text: "Example content 3" }],
|
258
|
+
close: "item"
|
259
|
+
}],
|
260
|
+
close: "collapsible_list"
|
261
|
+
},
|
262
|
+
{ text: "\n<p>Some more text</p>\n" }
|
263
|
+
])
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|