csl 1.2.0 → 1.2.1

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: d1cbdc6b606bf9f4652ad841cafd83edfc774fd2
4
- data.tar.gz: 7f55aee76c232b8f3760ffa99a47e6f2ef7c7712
3
+ metadata.gz: 0dd57180de9ed4d48bb5ce00393929be63df55fe
4
+ data.tar.gz: c20b280f2e9ec6f596d0453fc4862e23cbf50dec
5
5
  SHA512:
6
- metadata.gz: e5c6c2daa0db1832bfcd0c6d63bf61fe7602818dfb233b4e6d05394695412b760bfbf09b312699f48f33e78e3685ccacd429c2e61d1acac1644b1e40df650ae5
7
- data.tar.gz: 4b33db0d2bf6d84e0ee85d4327d227f19ee9e958d63c0c016a2a40db92392aa9e6b860b0a283336bfccba42390605acbcf381f08e20ffbeac376d3d17e7b6fb7
6
+ metadata.gz: 4d3ddca5ec5ab21e0d9e4ec973356e76f4abae8bf6b75868d7d4ffa7a10bd3853f510f280497302f3cc36f342a58f5238ab3650dc180085d36a595d21a2de4bc
7
+ data.tar.gz: 2a6911020b2bedc729617cb95c88db7184c5447d897f52d8ebc6ac84dbfd5f92b12a6cba54f78fe871f361eb48b37b4abc3a44b379493c6cb99000595a6d04da
data/csl.gemspec CHANGED
@@ -4,6 +4,12 @@ $:.unshift lib unless $:.include?(lib)
4
4
 
5
5
  require 'csl/version'
6
6
 
7
+ EXCLUDES = %w{
8
+ .coveralls.yml
9
+ .travis.yml
10
+ .csl.gemspec
11
+ }
12
+
7
13
  Gem::Specification.new do |s|
8
14
  s.name = 'csl'
9
15
  s.version = CSL::VERSION.dup
@@ -26,7 +32,7 @@ Gem::Specification.new do |s|
26
32
 
27
33
  s.add_dependency('namae', ['~>0.7'])
28
34
 
29
- s.files = `git ls-files`.split("\n")
35
+ s.files = `git ls-files`.split("\n") - EXCLUDES
30
36
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
31
37
  s.executables = []
32
38
  s.require_path = 'lib'
data/lib/csl/loader.rb CHANGED
@@ -18,45 +18,17 @@ module CSL
18
18
  # Locale.load('http://example.com/de.xml') -> locale
19
19
  #
20
20
  # Resolves the passed-in path/name or string and loads the asset data.
21
- # The data will be passed on to the #parse method of the base class.
21
+ # The data will be passed on to the #parse! method of the base class.
22
22
  # Typically, this will return a new instance of the class.
23
23
  #
24
24
  # @note
25
- # The base class is expected to define a #parse method.
25
+ # The base class is expected to define a #parse! method.
26
26
  #
27
27
  # @raise ParseError
28
28
  #
29
29
  # @return [Style, Locale] the parsed CSL resource
30
30
  def load(input)
31
- case
32
- when input.respond_to?(:read)
33
- data = input.read
34
- when input.to_s =~ /^\s*</
35
- data = input.to_s
36
- else
37
-
38
- input = input.to_s
39
-
40
- case
41
- when File.exists?(input)
42
- location = input
43
- when File.exists?(extend_name(input))
44
- location = extend_name(input)
45
- when File.exists?(extend_path(input))
46
- location = extend_path(input)
47
- else
48
- location = input
49
- end
50
-
51
- Kernel.open(location, 'r:UTF-8') do |io|
52
- data = io.read
53
- end
54
- end
55
-
56
- parse(data)
57
-
58
- rescue => e
59
- raise ParseError, "failed to load #{input.inspect}: #{e.message}"
31
+ parse! extract_data_from(input)
60
32
  end
61
33
 
62
34
  def list
@@ -86,6 +58,37 @@ module CSL
86
58
 
87
59
  name
88
60
  end
61
+
62
+ private
63
+
64
+ def extract_data_from(input)
65
+ case
66
+ when input.respond_to?(:read)
67
+ input.read
68
+ when input.to_s =~ /^\s*</
69
+ input.to_s
70
+ else
71
+
72
+ input = input.to_s
73
+
74
+ case
75
+ when File.exists?(input)
76
+ location = input
77
+ when File.exists?(extend_name(input))
78
+ location = extend_name(input)
79
+ when File.exists?(extend_path(input))
80
+ location = extend_path(input)
81
+ else
82
+ location = input
83
+ end
84
+
85
+ Kernel.open(location, 'r:UTF-8') do |io|
86
+ io.read
87
+ end
88
+ end
89
+ rescue => e
90
+ raise ParseError, "failed to extract CSL data from #{input.inspect}: #{e.message}"
91
+ end
89
92
  end
90
93
 
91
94
  end
data/lib/csl/parser.rb CHANGED
@@ -11,7 +11,9 @@ module CSL
11
11
  @engines = {
12
12
  :nokogiri => lambda { |source|
13
13
  Nokogiri::XML::Document.parse(source, nil, nil,
14
- Nokogiri::XML::ParseOptions::DEFAULT_XML | Nokogiri::XML::ParseOptions::NOBLANKS | Nokogiri::XML::ParseOptions::NOENT)
14
+ Nokogiri::XML::ParseOptions::DEFAULT_XML |
15
+ Nokogiri::XML::ParseOptions::NOBLANKS |
16
+ Nokogiri::XML::ParseOptions::NOENT)
15
17
  },
16
18
  :default => lambda { |source|
17
19
  REXML::Document.new(source, :compress_whitespace => :all, :ignore_whitespace_nodes => :all)
@@ -68,7 +70,7 @@ module CSL
68
70
  scope = specialize_scope(root, scope)
69
71
 
70
72
  node.children.each do |child|
71
- root << parse_tree(child, scope) unless comment?(child)
73
+ root << parse_tree(child, scope) unless skip?(child)
72
74
  end unless root.textnode?
73
75
 
74
76
  root
@@ -79,7 +81,12 @@ module CSL
79
81
  node.has_text? && node.text
80
82
  else
81
83
  child = node.children[0]
82
- child && child.respond_to?(:text?) && child.text? && child.text
84
+ return unless child && child.respond_to?(:text?) && child.text?
85
+
86
+ text = child.text
87
+ return if text.to_s.strip.empty?
88
+
89
+ text
83
90
  end
84
91
  end
85
92
 
@@ -88,7 +95,18 @@ module CSL
88
95
  node.respond_to?(:node_type) &&
89
96
  [:comment, :xmldecl, :processing_instruction, 7].include?(node.node_type)
90
97
  end
91
- alias skip? comment?
98
+
99
+ def text?(node)
100
+ if defined?(Nokogiri)
101
+ node.is_a?(Nokogiri::XML::Text)
102
+ else
103
+ false
104
+ end
105
+ end
106
+
107
+ def skip?(node)
108
+ comment?(node) || text?(node)
109
+ end
92
110
 
93
111
  def specialize_scope(root, scope = Node)
94
112
  case root
data/lib/csl/treelike.rb CHANGED
@@ -388,6 +388,10 @@ module CSL
388
388
  def empty?
389
389
  all?(&:nil?)
390
390
  end
391
+
392
+ def select(&block)
393
+ each.select(&block)
394
+ end
391
395
 
392
396
  # Adds the node as a child node. Raises ValidationError if none
393
397
  # of the Struct members matches the node's name. If there is
data/lib/csl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CSL
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.2.1'.freeze
3
3
  end
@@ -36,6 +36,26 @@ module CSL
36
36
  end
37
37
  end
38
38
 
39
+ describe 'for an empty name node' do
40
+ ['<name/>', '<name></name>', '<name> </name>'].each do |source|
41
+ it "returns a Style::Name for #{source.inspect} by default" do
42
+ Parser.instance.parse!(source).should be_a(Style::Name)
43
+ end
44
+
45
+ it "returns a Style::Name for #{source.inspect} for Style scope" do
46
+ Parser.instance.parse!(source, Style).should be_a(Style::Name)
47
+ end
48
+
49
+ it "returns a Node for #{source.inspect} for Locale scope" do
50
+ Parser.instance.parse!(source, Locale).should be_a(Node)
51
+ end
52
+
53
+ it "returns an Info::Name for #{source.inspect} for Info scope" do
54
+ Parser.instance.parse!(source, Info).should be_a(Info::Name)
55
+ end
56
+ end
57
+ end
58
+
39
59
  describe 'for <foo bar="x"/>' do
40
60
  let(:source) { '<foo bar="x"/>' }
41
61
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvester Keil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-12 00:00:00.000000000 Z
11
+ date: 2014-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: namae
@@ -32,12 +32,10 @@ executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
- - .coveralls.yml
36
35
  - .document
37
36
  - .gitignore
38
37
  - .rspec
39
38
  - .simplecov
40
- - .travis.yml
41
39
  - .yardopts
42
40
  - AGPL
43
41
  - BSDL
@@ -141,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
139
  version: '0'
142
140
  requirements: []
143
141
  rubyforge_project:
144
- rubygems_version: 2.0.14
142
+ rubygems_version: 2.2.2
145
143
  signing_key:
146
144
  specification_version: 4
147
145
  summary: A Ruby CSL parser and library
data/.coveralls.yml DELETED
@@ -1 +0,0 @@
1
- service_name: travis-ci
data/.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- language: ruby
2
- bundler_args: --without debug extra
3
- script: bundle exec rake test_with_coveralls
4
- rvm:
5
- - 2.1.0
6
- - 2.0.0
7
- - 1.9.3
8
- - jruby-19mode
9
- - jruby-head
10
- - rbx
11
- notifications:
12
- email:
13
- recipients:
14
- - sylvester@keil.or.at
15
- on_success: change
16
- on_failure: always