xan_markup 0.3.0 → 0.4.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
  SHA1:
3
- metadata.gz: 6bac1b66d447ed5e88d8706b419f4e9cbc5280d1
4
- data.tar.gz: 8b8c50c6337d5eec7845ab11f489f0e948c31381
3
+ metadata.gz: 05e381a7deb5e0db42d2d827db4c345e0728b6a3
4
+ data.tar.gz: 6396514774a171c956838a90c367cf526a000826
5
5
  SHA512:
6
- metadata.gz: 181471f68d534fe74cb745539b172b05b2d947146c9502516f3e70e3230ceae78cd9fd302fd072d59b411f7a093d5c276f6cc9205eec62ff9b9c9220efc85e2c
7
- data.tar.gz: 4462fb72d76f8c5987f0289511a69777b9d14cc65532e78e5ac392e5bc0e37ef976939e89d3705baa911caac39306ad159450e55f1b5314108834539160c42ce
6
+ metadata.gz: 598c3883525b6a7eaa3a1cffc92e1fc88c14d9ecc65e0b321802e7335eb724b52e90b77bc023a57ede7ce8cdc229ec086a712ef24d14ba6bc5f61b83785978aa
7
+ data.tar.gz: 33ad82ca24d68cde245a9be6577e52e737a77cbbee04dbb5d2c143fdd698419f7f005c1498d81c381393fcec2d76e0896f44b4979b5071e214cb709f39e5e8ba
data/Gemfile.lock CHANGED
@@ -1,23 +1,67 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- diff-lcs (1.2.1)
5
- git (1.2.9.1)
6
- jeweler (1.8.4)
7
- bundler (~> 1.0)
4
+ addressable (2.4.0)
5
+ builder (3.2.3)
6
+ descendants_tracker (0.0.4)
7
+ thread_safe (~> 0.3, >= 0.3.1)
8
+ diff-lcs (1.3)
9
+ faraday (0.9.2)
10
+ multipart-post (>= 1.2, < 3)
11
+ git (1.3.0)
12
+ github_api (0.16.0)
13
+ addressable (~> 2.4.0)
14
+ descendants_tracker (~> 0.0.4)
15
+ faraday (~> 0.8, < 0.10)
16
+ hashie (>= 3.4)
17
+ mime-types (>= 1.16, < 3.0)
18
+ oauth2 (~> 1.0)
19
+ hashie (3.5.7)
20
+ highline (1.7.10)
21
+ jeweler (2.3.7)
22
+ builder
23
+ bundler (>= 1)
8
24
  git (>= 1.2.5)
25
+ github_api (~> 0.16.0)
26
+ highline (>= 1.6.15)
27
+ nokogiri (>= 1.5.10)
28
+ psych (~> 2.2)
9
29
  rake
10
30
  rdoc
11
- rake (10.4.2)
12
- rdoc (4.0.0)
13
- rspec (2.13.0)
14
- rspec-core (~> 2.13.0)
15
- rspec-expectations (~> 2.13.0)
16
- rspec-mocks (~> 2.13.0)
17
- rspec-core (2.13.1)
18
- rspec-expectations (2.13.0)
19
- diff-lcs (>= 1.1.3, < 2.0)
20
- rspec-mocks (2.13.0)
31
+ semver2
32
+ jwt (1.5.6)
33
+ mime-types (2.99.3)
34
+ mini_portile2 (2.3.0)
35
+ multi_json (1.12.2)
36
+ multi_xml (0.6.0)
37
+ multipart-post (2.0.0)
38
+ nokogiri (1.8.1)
39
+ mini_portile2 (~> 2.3.0)
40
+ oauth2 (1.4.0)
41
+ faraday (>= 0.8, < 0.13)
42
+ jwt (~> 1.0)
43
+ multi_json (~> 1.3)
44
+ multi_xml (~> 0.5)
45
+ rack (>= 1.2, < 3)
46
+ psych (2.2.4)
47
+ rack (2.0.3)
48
+ rake (12.3.0)
49
+ rdoc (6.0.1)
50
+ rspec (3.7.0)
51
+ rspec-core (~> 3.7.0)
52
+ rspec-expectations (~> 3.7.0)
53
+ rspec-mocks (~> 3.7.0)
54
+ rspec-core (3.7.0)
55
+ rspec-support (~> 3.7.0)
56
+ rspec-expectations (3.7.0)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.7.0)
59
+ rspec-mocks (3.7.0)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.7.0)
62
+ rspec-support (3.7.0)
63
+ semver2 (3.4.2)
64
+ thread_safe (0.3.6)
21
65
 
22
66
  PLATFORMS
23
67
  ruby
@@ -27,3 +71,6 @@ DEPENDENCIES
27
71
  jeweler
28
72
  rdoc
29
73
  rspec
74
+
75
+ BUNDLED WITH
76
+ 1.16.0
data/README.md CHANGED
@@ -32,6 +32,24 @@ You can pass attributes to tags
32
32
  ....
33
33
  end
34
34
 
35
+ ## Block
36
+
37
+ {{block}}This is my favorite movie{{/block}}
38
+
39
+ def markup_block(content: "")
40
+ content.upcase
41
+ end
42
+
43
+ ### Nesting is supported only for unique tags.
44
+
45
+ You can:
46
+
47
+ {{block}} this {{normal_tag}} {{/block}}
48
+ {{block}} and {{block2}} nesting {{/block2}} {{/block}}
49
+
50
+ You can't (currently):
51
+
52
+ {{block}}{{block}}{{/block}}{{/block}}
35
53
 
36
54
  ## Customization
37
55
 
@@ -55,7 +73,7 @@ For example using instance variables not helper methods:
55
73
  Markupizer.new(content).markupize &MyCustomCaller.new(self).call
56
74
  end
57
75
 
58
- You can change also syntax
76
+ You can change also syntax (See MarkupSyntax and BlockMarkupSyntax in markupizer.rb)
59
77
 
60
78
  def markupize(content)
61
79
  Markupizer.new(content, /\[ ?(.*?) ?\]/).markupize &MyCustomCaller.new(self).call
@@ -64,4 +82,4 @@ You can change also syntax
64
82
  @favorite_movie = "Matrix"
65
83
  markupize("My favorite movie is [favorite_movie]") #=> My favorite movie is Matrix
66
84
 
67
- Copyright (c) 2009-20015 Grzegorz Derebecki, released under the MIT license
85
+ Copyright (c) 2009-2018 Grzegorz Derebecki, released under the MIT license
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -0,0 +1,13 @@
1
+ module XanMarkup
2
+ class ContentTag < Tag
3
+ attr_reader :content
4
+ def initialize(tag, content)
5
+ @tag = tag
6
+ @content = content
7
+ end
8
+
9
+ def args
10
+ super.merge(content: content)
11
+ end
12
+ end
13
+ end
@@ -1,23 +1,35 @@
1
1
  require 'xan_markup/tag'
2
+ require 'xan_markup/content_tag'
2
3
 
3
4
  module XanMarkup
4
5
  class Markupizer
5
6
  MarkupSyntax = /\{\{ ?(.*?) ?\}\}/
7
+ BlockMarkupSyntax = /\{\{ ?((\w+)(.*?)) ?\}\}(.*?)\{\{ ?\/(\2) ?\}\}/
6
8
 
7
- def initialize(content, syntax = MarkupSyntax)
9
+ def initialize(content, syntax = MarkupSyntax, block_syntax = BlockMarkupSyntax)
8
10
  @content = content.to_s.dup.to_str
9
11
  @syntax = syntax
12
+ @block_syntax = block_syntax
10
13
  end
11
14
 
12
15
  def tags
13
- @content.scan(@syntax).map do |markup|
14
- Tag.new(markup.first)
15
- end
16
+ tags = []
17
+ markupize { |tag| tags << tag }
18
+ tags
19
+ end
20
+
21
+ def markupize(content = @content, &block)
22
+ content = markupize_syntax(@block_syntax, content, &block)
23
+ markupize_syntax(@syntax, content, &block)
16
24
  end
17
25
 
18
- def markupize
19
- @content.gsub(@syntax) do |markup|
20
- yield Tag.new($1)
26
+ def markupize_syntax(syntax, content, &block)
27
+ content.gsub(syntax) do |markup|
28
+ if content = $4
29
+ yield ContentTag.new($1, markupize(content, &block))
30
+ else
31
+ yield Tag.new($1)
32
+ end
21
33
  end
22
34
  end
23
35
  end
data/spec/spec_helper.rb CHANGED
@@ -7,6 +7,4 @@ require "xan_markup"
7
7
  # in ./support/ and its subdirectories.
8
8
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
9
 
10
- RSpec.configure do |config|
11
-
12
- end
10
+ RSpec::Expectations.configuration.on_potential_false_positives = :nothing
@@ -21,7 +21,7 @@ module XanMarkup
21
21
  let(:helper) { TestHelper.new }
22
22
 
23
23
  it "should call property method when found tag" do
24
- helper.should_receive(:markup_test)
24
+ expect(helper).to receive(:markup_test)
25
25
  helper.markupize("this is markup {{test}} tag")
26
26
  end
27
27
 
@@ -30,12 +30,12 @@ module XanMarkup
30
30
  end
31
31
 
32
32
  it "should return text that tag is not defined" do
33
- helper.markupize("this is markup {{ test }} tag").should include("missing tag: test")
33
+ expect(helper.markupize("this is markup {{ test }} tag")).to include("missing tag: test")
34
34
  end
35
35
 
36
36
  it "should replace tag with content returned by markup markupizer" do
37
- helper.stub(:markup_best_language).and_return("Ruby")
38
- helper.markupize("Best language is: {{ best_language }}").should include("Ruby")
37
+ allow(helper).to receive_messages(markup_best_language: "Ruby")
38
+ expect(helper.markupize("Best language is: {{ best_language }}")).to include("Ruby")
39
39
  end
40
40
  end
41
41
 
@@ -44,48 +44,69 @@ module XanMarkup
44
44
 
45
45
  it "should replace content with data returned from block" do
46
46
  markupizer = Markupizer.new("this is markup {{test}} tag")
47
- markupizer.markupize {|tag| "SUPER" }.should include("SUPER")
47
+ expect(markupizer.markupize {|tag| "SUPER" }).to include("SUPER")
48
48
  end
49
49
 
50
+ it "should allow block tag" do
51
+ markupizer = Markupizer.new("this is markup {{test}}tag{{/test}}")
52
+ expect(markupizer.markupize {|tag| tag.content.upcase }).to include("TAG")
53
+ end
54
+
55
+ it "should allow nestd block tags" do
56
+ markupizer = Markupizer.new("{{test}}tag {{test2}}test2{{/test2}}{{/test}}")
57
+ expect(markupizer.markupize {|tag| tag.content.upcase }).to eq("TAG TEST2")
58
+ end
59
+
60
+ it "should allow multiple identical tags in the same content" do
61
+ markupizer = Markupizer.new("{{test}}A{{/test}} {{test}}B{{/test}}")
62
+ expect(markupizer.markupize {|tag| tag.content }).to eq("A B")
63
+ end
64
+
65
+ it "should return two block tags" do
66
+ markupizer = Markupizer.new('this is {{a}}A{{/a}} markup {{b}}B{{/b}}')
67
+ expect(markupizer.tags.size).to eq(2)
68
+ end
69
+
70
+
71
+
50
72
  it "should return two tags (whitespaces allowed)" do
51
73
  markupizer = Markupizer.new('this is {{awesome}} markup {{test}}')
52
- markupizer.should have(2).tags
74
+ expect(markupizer.tags.size).to eq(2)
53
75
  end
54
76
 
55
77
  it "should return tag even when whitespace inside tag is used" do
56
78
  markupizer = Markupizer.new('this is markup {{ test }} tag')
57
- markupizer.should have(1).tags
79
+ expect(markupizer.tags.size).to eq(1)
58
80
  end
59
81
 
60
82
  it "should give tag object with proper name" do
61
83
  markupizer = Markupizer.new('this is markup {{test name="xan"}} tag')
62
- markupizer.tags.first.name.should == "test"
84
+ expect(markupizer.tags.first.name).to eq("test")
63
85
  end
64
86
 
65
87
  it "should give tag object with proper args" do
66
88
  markupizer = Markupizer.new('this is markup {{test name="xan"}}')
67
- markupizer.tags.first.args.should == {name: "xan"}
89
+ expect(markupizer.tags.first.args).to eq(name: "xan")
68
90
  end
69
91
 
70
92
  it "should give tag args when using single quotes" do
71
93
  markupizer = Markupizer.new("this is markup {{test name='xan'}} tag")
72
- markupizer.tags.first.args.should == {name: "xan"}
94
+ expect(markupizer.tags.first.args).to eq(name: "xan")
73
95
  end
74
96
 
75
97
  it "should give tag args when quotes are skipped" do
76
98
  markupizer = Markupizer.new("this is markup {{test name=xan}} tag")
77
- markupizer.tags.first.args.should == {name: "xan"}
99
+ expect(markupizer.tags.first.args).to eq(name: "xan")
78
100
  end
79
101
 
80
102
  it "should works with classes that inherance from string" do
81
103
  markupizer = Markupizer.new SafeBuffer.new("{{test}}")
82
- markupizer.should have(1).tags
104
+ expect(markupizer.tags.size).to eq(1)
83
105
  end
84
106
 
85
107
  it "should allow change syntax" do
86
108
  markupizer = Markupizer.new "[test]", /\[ ?(.*?) ?\]/
87
- markupizer.should have(1).tags
109
+ expect(markupizer.tags.size).to eq(1)
88
110
  end
89
-
90
111
  end
91
112
  end
data/xan_markup.gemspec CHANGED
@@ -2,18 +2,18 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: xan_markup 0.3.0 ruby lib
5
+ # stub: xan_markup 0.4.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
- s.name = "xan_markup"
9
- s.version = "0.3.0"
8
+ s.name = "xan_markup".freeze
9
+ s.version = "0.4.0"
10
10
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Grzegorz Derebecki"]
14
- s.date = "2015-02-10"
15
- s.description = "Simple tag parser"
16
- s.email = "grzegorz.derebecki@fdb.pl"
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Grzegorz Derebecki".freeze]
14
+ s.date = "2018-01-02"
15
+ s.description = "Simple tag parser".freeze
16
+ s.email = "grzegorz.derebecki@fdb.pl".freeze
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE.txt",
19
19
  "README.md"
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "VERSION",
30
30
  "lib/xan_markup.rb",
31
31
  "lib/xan_markup/caller.rb",
32
+ "lib/xan_markup/content_tag.rb",
32
33
  "lib/xan_markup/helper.rb",
33
34
  "lib/xan_markup/markupizer.rb",
34
35
  "lib/xan_markup/tag.rb",
@@ -36,30 +37,30 @@ Gem::Specification.new do |s|
36
37
  "spec/xan_markup/helper_spec.rb",
37
38
  "xan_markup.gemspec"
38
39
  ]
39
- s.homepage = "http://github.com/madmax/xan_markup"
40
- s.licenses = ["MIT"]
41
- s.rubygems_version = "2.2.2"
42
- s.summary = "simple tag parser"
40
+ s.homepage = "http://github.com/madmax/xan_markup".freeze
41
+ s.licenses = ["MIT".freeze]
42
+ s.rubygems_version = "2.6.11".freeze
43
+ s.summary = "simple tag parser".freeze
43
44
 
44
45
  if s.respond_to? :specification_version then
45
46
  s.specification_version = 4
46
47
 
47
48
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
- s.add_development_dependency(%q<rspec>, [">= 0"])
49
- s.add_development_dependency(%q<bundler>, [">= 0"])
50
- s.add_development_dependency(%q<jeweler>, [">= 0"])
51
- s.add_development_dependency(%q<rdoc>, [">= 0"])
49
+ s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
50
+ s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
51
+ s.add_development_dependency(%q<jeweler>.freeze, [">= 0"])
52
+ s.add_development_dependency(%q<rdoc>.freeze, [">= 0"])
52
53
  else
53
- s.add_dependency(%q<rspec>, [">= 0"])
54
- s.add_dependency(%q<bundler>, [">= 0"])
55
- s.add_dependency(%q<jeweler>, [">= 0"])
56
- s.add_dependency(%q<rdoc>, [">= 0"])
54
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
55
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
56
+ s.add_dependency(%q<jeweler>.freeze, [">= 0"])
57
+ s.add_dependency(%q<rdoc>.freeze, [">= 0"])
57
58
  end
58
59
  else
59
- s.add_dependency(%q<rspec>, [">= 0"])
60
- s.add_dependency(%q<bundler>, [">= 0"])
61
- s.add_dependency(%q<jeweler>, [">= 0"])
62
- s.add_dependency(%q<rdoc>, [">= 0"])
60
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
61
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
62
+ s.add_dependency(%q<jeweler>.freeze, [">= 0"])
63
+ s.add_dependency(%q<rdoc>.freeze, [">= 0"])
63
64
  end
64
65
  end
65
66
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xan_markup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grzegorz Derebecki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-10 00:00:00.000000000 Z
11
+ date: 2018-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -84,6 +84,7 @@ files:
84
84
  - VERSION
85
85
  - lib/xan_markup.rb
86
86
  - lib/xan_markup/caller.rb
87
+ - lib/xan_markup/content_tag.rb
87
88
  - lib/xan_markup/helper.rb
88
89
  - lib/xan_markup/markupizer.rb
89
90
  - lib/xan_markup/tag.rb
@@ -110,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  version: '0'
111
112
  requirements: []
112
113
  rubyforge_project:
113
- rubygems_version: 2.2.2
114
+ rubygems_version: 2.6.11
114
115
  signing_key:
115
116
  specification_version: 4
116
117
  summary: simple tag parser