xembly 0.3 → 0.4

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: aefd3284a7d99ffa9bc9b2d477263a1b47a220a3
4
- data.tar.gz: 1d795786c9081702f40b6aa43668af5d07964795
3
+ metadata.gz: 7d13f44b89daed33ea1f5225bb756ee791e25776
4
+ data.tar.gz: fa87b4c56484867037eb1d5fdf47f60cf2af938b
5
5
  SHA512:
6
- metadata.gz: f56633f3ed7ebe4f8feea6fe724d7f1a22a14e721a8f12e4665aadfcaf567fd43443f202c0eb91b8ac29dfdb22c7fad44a858d609c0a399b90976b28941aed52
7
- data.tar.gz: 033130d913d80d85d0f205ec519dfcd474d7626b1f3577f4dede4a54a283a11591cb830669deef211b2f3ea45f9088509be7f67d7d2348bd39f0f681702082e5
6
+ metadata.gz: 6ff45d3322febcd673bb205f8689ad8136a04676e64734ff9736ff848f50f0b89980495d57241c0e224f721918b948bd57de1b87a48f5a534eea34c2735c0829
7
+ data.tar.gz: b0c88f349598911c36247d229363c1adba7095417988b38e81d9f46bbf60e91823bd5188b4c926eb28b76e51171a7d4f252abf77434452975f04fd6d9855e1b6
data/features/cli.feature CHANGED
@@ -25,7 +25,7 @@ Feature: Command Line Processing
25
25
  XPATH "/books";
26
26
  ADD "book";
27
27
  ATTR "isbn", "1519166915";
28
- SET "Elegant Objects";
28
+ SET ""Elegant Objects; The Book"";
29
29
  UP;
30
30
  ADD "author";
31
31
  ADDIF "name";
@@ -39,7 +39,8 @@ Feature: Command Line Processing
39
39
  Then Exit code is zero
40
40
  And Stdout contains "reading text.xml"
41
41
  And XML file "out.xml" matches "/books[count(book) = 3]"
42
- And XML file "out.xml" matches "/books/book[@isbn='1519166915' and .='Elegant Objects']"
42
+ And XML file "out.xml" matches "/books/book[@isbn='1519166915']"
43
+ And XML file "out.xml" matches "/books/book[.='\"Elegant Objects; The Book\"']"
43
44
  And XML file "out.xml" matches "/books[author='yegor']"
44
45
  And XML file "out.xml" matches "/books[not(garbage)]"
45
46
 
@@ -66,11 +66,11 @@ Then(/^Stdout is empty$/) do
66
66
  fail "STDOUT is not empty:\n#{@stdout}" unless @stdout == ''
67
67
  end
68
68
 
69
- Then(/^XML file "([^"]+)" matches "([^"]+)"$/) do |file, xpath|
69
+ Then(/^XML file "([^"]+)" matches "((?:[^"]|\\")+)"$/) do |file, xpath|
70
70
  fail "File #{file} doesn't exit" unless File.exist?(file)
71
71
  xml = Nokogiri::XML.parse(File.read(file))
72
72
  xml.remove_namespaces!
73
- if xml.xpath(xpath).empty?
73
+ if xml.xpath(xpath.gsub(/\\"/, '"')).empty?
74
74
  fail "XML file #{file} doesn't match \"#{xpath}\":\n#{xml}"
75
75
  end
76
76
  end
@@ -37,8 +37,8 @@ module Xembly
37
37
  def initialize(text)
38
38
  @array = text
39
39
  .strip
40
- .split(/\s*;\s*/)
41
- .reject(&:empty?)
40
+ .scan(/([A-Za-z]+)(?:\s+"([^"]+)")?(?:\s*,\s*"([^"]+)")*\s*;/)
41
+ .map { |t| t.reject(&:nil?) }
42
42
  .map { |t| Directives.map(t) }
43
43
  end
44
44
 
@@ -50,13 +50,9 @@ module Xembly
50
50
  @array.length
51
51
  end
52
52
 
53
- def self.map(text)
54
- cmd, tail = text.strip.split(/\s+/, 2)
55
- args = (tail.nil? ? '' : tail).strip
56
- .scan(/"([^"]+)"/)
57
- .flatten
58
- .map { |a| a.tr('"', '') }
59
- case cmd.upcase
53
+ def self.map(cmd)
54
+ args = cmd.drop(1)
55
+ case cmd[0].upcase
60
56
  when 'ADD'
61
57
  Add.new(args[0])
62
58
  when 'ADDIF'
data/lib/xembly/set.rb CHANGED
@@ -20,6 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require 'nokogiri'
23
24
  require 'xembly'
24
25
 
25
26
  module Xembly
@@ -33,7 +34,7 @@ module Xembly
33
34
 
34
35
  def exec(_, cursor)
35
36
  cursor.each do |node|
36
- node.content = @value
37
+ node.content = Nokogiri::HTML.parse(@value).text
37
38
  Xembly.log.info "node \"#{node.name}\" text content set"
38
39
  end
39
40
  cursor
@@ -25,5 +25,5 @@
25
25
  # Copyright:: Copyright (c) 2016 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Xembly
28
- VERSION = '0.3'
28
+ VERSION = '0.4'
29
29
  end
data/lib/xembly.rb CHANGED
@@ -73,7 +73,7 @@ module Xembly
73
73
  dirs = File.read(@opts[:dirs])
74
74
  else
75
75
  Xembly.log.info "#{@opts.arguments.length} directives in command line"
76
- dirs = @opts.arguments.join(';')
76
+ dirs = @opts.arguments.join('')
77
77
  end
78
78
  Xembler.new(Directives.new(dirs)).apply(xml).to_xml
79
79
  end
@@ -31,8 +31,8 @@ require 'xembly/directives'
31
31
  class TestDirectives < Minitest::Test
32
32
  def test_parses_directives
33
33
  dirs = Xembly::Directives.new(
34
- " ADD \"book\" ; ATTR 'a1', 'works, for\nme!'; "
34
+ " ADD \"book;&quot;me\";UP;ATTR \"a1\", \"works, for\nme!\"; "
35
35
  )
36
- assert dirs.length == 2, 'two directives must be there'
36
+ assert dirs.length == 3, 'three directives must be there'
37
37
  end
38
38
  end
data/test/test_xembler.rb CHANGED
@@ -34,7 +34,7 @@ class TestXembler < XeTest
34
34
  def test_modifies_xml
35
35
  xembler = Xembly::Xembler.new(
36
36
  Xembly::Directives.new(
37
- 'XPATH "/books"; ADD "book"; ADD "test"; UP; ADD "title"; SET "hi";'
37
+ 'XPATH "/books"; ADD "book"; ADD "test"; UP; ADD "title"; SET "hi;you";'
38
38
  )
39
39
  )
40
40
  matches(
@@ -42,7 +42,8 @@ class TestXembler < XeTest
42
42
  [
43
43
  '/*',
44
44
  '/books[count(book)=1]',
45
- '/books/book[test and title]'
45
+ '/books/book[test and title]',
46
+ '/books/book/title[.="hi;you"]'
46
47
  ]
47
48
  )
48
49
  end
data/test/test_xembly.rb CHANGED
@@ -33,7 +33,7 @@ require 'test__helper'
33
33
  # License:: MIT
34
34
  class TestXembly < XeTest
35
35
  def test_basic
36
- opts = opts(['-x', '/dev/null', 'ADD "books"', 'ADD "book"'])
36
+ opts = opts(['-x', '/dev/null', 'ADD "books";', 'ADD "book";'])
37
37
  matches(
38
38
  Xembly::Base.new(opts).xml,
39
39
  [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xembly
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-19 00:00:00.000000000 Z
11
+ date: 2016-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri