xliffer 0.0.2 → 1.0.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: ea276a483651e8f0e534280a3fef9329a52c4321
4
- data.tar.gz: 141a20279f0de253021ecc64d8d7427b40ab4aec
3
+ metadata.gz: 104aa521b84201e154f07c5644d47f2ecbc8d0cc
4
+ data.tar.gz: 6b27b0b839f4357043d4cd273b0bc1a048f84d51
5
5
  SHA512:
6
- metadata.gz: ce7148866423e954f0febc89505518ad0110a8bc075fea789f25174f0b2ca27dcda2339f3c393f20ddf7d63eabf3c053610fb7e03ae9f47dcea0c24641127c7c
7
- data.tar.gz: 334fed09e496be5d4770ae67ab3113491458e7f58acf744121ffeaab221220532078c4e225d9ebfb8157bd332d405ec1a2ac2e22afa6966343c60b96499d3f44
6
+ metadata.gz: 207f2eaabf1ab6376e2a5dc048b564ce959f66379a01568b0948f9a27c185534584f6e6d4046114e49cd1c301f817de2c731fd91c218078320664bac099fd03d
7
+ data.tar.gz: 24fa0d4d45f33e79a1f5dd4c963fbaa91280e845a9024e604d2e1ee0e0fd3b89c4f5fc80c9a592b6ac69e9cf72113497ace3a2c14215daffc062013101aaa32d
data/.gitignore CHANGED
@@ -13,6 +13,7 @@ spec/reports
13
13
  test/tmp
14
14
  test/version_tmp
15
15
  tmp
16
+ Gemfile.lock
16
17
 
17
18
  # YARD artifacts
18
19
  .yardoc
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
1
  --color
2
- --format progress
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.2.2"
4
+ - "2.1.6"
5
+ - "2.0.0"
6
+ - "1.9.3"
7
+ - "1.8.7"
8
+ - jruby-18mode
9
+ - jruby-19mode
10
+ - rbx
11
+ script: bundle exec rspec
12
+ addons:
13
+ code_climate:
14
+ repo_token: 9b727c6d136a1a4df7f854f727b158557077e709e843304400542a4e17bf9c7d
data/Gemfile CHANGED
@@ -1,7 +1,15 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'nokogiri'
3
+ gem 'nokogiri', '~> 1.5.10'
4
+ gem 'equivalent-xml'
5
+
6
+ group :test do
7
+ unless RUBY_VERSION.match(/\A1\.8/)
8
+ gem "codeclimate-test-reporter", :require => false
9
+ end
10
+ end
4
11
 
5
12
  group :development do
6
13
  gem 'rspec', '~> 2'
14
+ gem 'simplecov', '>= 0.9.0'
7
15
  end
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Portions copyright (c) 2015 Felipe Tanus
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,3 +1,8 @@
1
+ [![Build Status](https://travis-ci.org/fotanus/xliffer.svg?branch=master)](https://travis-ci.org/fotanus/xliffer)
2
+ [![Test Coverage](https://codeclimate.com/github/fotanus/xliffer/badges/coverage.svg)](https://codeclimate.com/github/fotanus/xliffer/coverage)
3
+ [![Code Climate](https://codeclimate.com/github/fotanus/xliffer/badges/gpa.svg)](https://codeclimate.com/github/fotanus/xliffer)
4
+
5
+
1
6
  xliffer
2
7
  =======
3
8
 
@@ -1,3 +1,3 @@
1
1
  module XLIFFer
2
- VERSION = "0.0.2"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -7,22 +7,18 @@ module XLIFFer
7
7
  attr_reader :source_language, :target_language, :original, :strings
8
8
  alias_method :file_name, :original
9
9
  def initialize(xml)
10
- unless xml_element?(xml) and file?(xml)
10
+ unless XLIFF::xml_element?(xml) and file?(xml)
11
11
  raise ArgumentError, "can't create a File without a file subtree"
12
12
  end
13
13
 
14
14
  @original = xml.attr("original")
15
15
  @source_language = xml.attr("source-language")
16
16
  @target_language = xml.attr("target-language")
17
- @strings = xml.xpath('.//trans-unit').map{|tu| String.new(tu)}
17
+ @strings = xml.xpath('.//trans-unit').map{|tu| String.new(tu) }
18
18
  end
19
19
 
20
20
 
21
21
  private
22
- # TODO: move to public method on XLIFF
23
- def xml_element?(xml)
24
- xml.kind_of? Nokogiri::XML::Element
25
- end
26
22
 
27
23
  def file?(xml)
28
24
  xml.name.downcase == "file"
@@ -2,42 +2,49 @@ module XLIFFer
2
2
  class XLIFF
3
3
  class String
4
4
  attr_reader :id, :source, :target, :note
5
- def initialize(xml)
6
- unless xml_element?(xml) and trans_unit?(xml)
5
+ def initialize(trans_unit_xml)
6
+ unless XLIFF::xml_element?(trans_unit_xml) and trans_unit?(trans_unit_xml)
7
7
  raise ArgumentError, "can't create a String without a trans-unit subtree"
8
8
  end
9
9
 
10
- @id = xml.attr('id')
11
- @source = get_source(xml)
12
- @target = get_target(xml)
13
- @note = get_note(xml)
10
+ @xml = trans_unit_xml
11
+ @id = @xml.attr('id')
12
+ @source = get_source
13
+ @target = get_target
14
+ @note = get_note
14
15
  end
15
16
 
16
- private
17
- # TODO: move to public method on XLIFF
18
- def xml_element?(xml)
19
- xml.kind_of? Nokogiri::XML::Element
17
+ def target=(val)
18
+ target = @xml.xpath('./target')
19
+ target.first.content = val
20
+ @target = val
20
21
  end
21
22
 
23
+ private
24
+
22
25
  def trans_unit?(xml)
23
26
  xml.name.downcase == "trans-unit"
24
27
  end
25
28
 
26
- def get_source(xml)
27
- sources = xml.xpath("./source")
29
+ def get_source
30
+ sources = @xml.xpath("./source")
28
31
  raise MultipleElement, "Should have only one source tag" if sources.size > 1
29
32
  raise NoElement, "Should have one source tag" unless sources.size == 1
30
33
  sources.first.text
31
34
  end
32
35
 
33
- def get_target(xml)
34
- targets = xml.xpath("./target")
36
+ def get_target
37
+ targets = @xml.xpath("./target")
35
38
  raise MultipleElement, "Should have only one target tag" if targets.size > 1
36
- targets.first ? targets.first.text : ''
39
+ if targets.empty?
40
+ targets << Nokogiri::XML::Node.new('target', @xml)
41
+ @xml.add_child(targets.first)
42
+ end
43
+ targets.first.text
37
44
  end
38
45
 
39
- def get_note(xml)
40
- notes = xml.xpath("./note")
46
+ def get_note
47
+ notes = @xml.xpath("./note")
41
48
  raise MultipleElement, "Should have only one target tag" if notes.size > 1
42
49
  notes.first ? notes.first.text : ''
43
50
  end
data/lib/xliffer/xliff.rb CHANGED
@@ -14,16 +14,20 @@ module XLIFFer
14
14
  parse(text)
15
15
  end
16
16
 
17
+ def to_xliff
18
+ @xml.to_xml
19
+ end
20
+
17
21
  private
18
22
  def parse(text)
19
23
  begin
20
- xml = Nokogiri::XML(text)
24
+ @xml = Nokogiri::XML(text)
21
25
  rescue
22
26
  fail FormatError, "Not a XML file"
23
27
  end
24
28
 
25
- xml.remove_namespaces!
26
- root = xml.xpath('/xliff')
29
+ @xml.remove_namespaces!
30
+ root = @xml.xpath('/xliff')
27
31
  raise FormatError, "Not a XLIFF file" unless root.any?
28
32
 
29
33
  @version = get_version(root)
@@ -39,5 +43,9 @@ module XLIFFer
39
43
  root.xpath('//file').map{|f| File.new(f)}
40
44
  end
41
45
 
46
+ def self.xml_element?(xml)
47
+ xml.kind_of? Nokogiri::XML::Element
48
+ end
49
+
42
50
  end
43
51
  end
@@ -1 +1 @@
1
- <xliff version="1.2"></xliff>
1
+ <xliff version="1.2"></xliff>
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,13 @@
1
+ unless RUBY_VERSION.match(/\A1\.8/)
2
+ require "codeclimate-test-reporter"
3
+ require 'simplecov'
4
+ CodeClimate::TestReporter.start
5
+ SimpleCov.start
6
+ end
7
+
8
+ require 'equivalent-xml'
9
+ require 'equivalent-xml/rspec_matchers'
10
+
1
11
  require 'xliffer'
2
12
 
3
13
  RSpec.configure do |config|
@@ -59,16 +59,30 @@ module XLIFFer
59
59
  end
60
60
  end
61
61
 
62
+ context "#strings" do
63
+ before(:all) do
64
+ @trans_unit = <<-EOF
65
+ <trans-unit id="my id">
66
+ <source>Hello World</source>
67
+ <target>Bonjour le monde</target>
68
+ </trans-unit>
69
+ EOF
70
+ end
62
71
 
63
- #context "#strings" do
64
- # before(:all) do
65
- # @trans_unit = <<-EOF
66
- # <trans-unit id="my id">
67
- # <source>Hello World</source>
68
- # <target>Bonjour le monde</target>
69
- # </trans-unit>
70
- # EOF
71
- # end
72
+ it 'Modify target' do
73
+ trans_unit_node = Nokogiri::XML.parse(@trans_unit).xpath("//trans-unit").first
74
+ string = XLIFF::String.new(trans_unit_node)
75
+ string.target = 'Hola Mundo'
76
+ string.target.should eq 'Hola Mundo'
77
+ end
78
+
79
+ it 'Modify target if xml doensnt contain target initially' do
80
+ xml = "<trans-unit id='my id'><source>Value</source></trans-unit>"
81
+ trans_unit_node = Nokogiri::XML.parse(xml).xpath("//trans-unit").first
82
+ string = XLIFF::String.new(trans_unit_node)
83
+ string.target = 'Hola Mundo'
84
+ string.target.should eq 'Hola Mundo'
85
+ end
72
86
  # it "is an array " do
73
87
  # trans_unit_node = Nokogiri::XML.parse("<xliff><file></file></xliff>").xpath("//file").first
74
88
  # XLIFF::File.new(trans_unit_node).strings.should be_kind_of(Array)
@@ -88,6 +102,6 @@ module XLIFFer
88
102
  # trans_unit_node = Nokogiri::XML.parse("<xliff><file>#{@trans_unit * 10}</file></xliff>").xpath("//file").first
89
103
  # XLIFF::File.new(trans_unit_node).strings.size.should eql(10)
90
104
  # end
91
- #end
105
+ end
92
106
  end
93
107
  end
@@ -55,5 +55,17 @@ module XLIFFer
55
55
  XLIFF.new('<xliff><file></file><file></file></xliff>').files.size.should eql(2)
56
56
  end
57
57
  end
58
+
59
+ context "#regenate" do
60
+ it 'should output an xml' do
61
+ xml = ::File.open("spec/files/empty.xliff").read
62
+ xliff = XLIFF.new(xml)
63
+ expect(xliff.to_xliff).to be_equivalent_to(xml)
64
+ end
65
+
66
+ it 'should contain modifications' do
67
+
68
+ end
69
+ end
58
70
  end
59
71
  end
data/xliffer.gemspec CHANGED
@@ -13,7 +13,11 @@ Gem::Specification.new do |s|
13
13
  s.email = 'fotanus@gmail.com'
14
14
  s.homepage = 'http://github.com/fotanus/xliff'
15
15
 
16
+ s.add_dependency "nokogiri", "~> 1.5"
17
+
16
18
  s.add_development_dependency "rspec", "~> 2"
19
+ s.add_development_dependency "simplecov", "~> 0.10"
20
+
17
21
  s.rubyforge_project = "xliffer"
18
22
 
19
23
  s.files = `git ls-files`.split("\n")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xliffer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Tanus
@@ -10,6 +10,20 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2012-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rspec
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.10'
27
55
  description: A parser for XLIFF files
28
56
  email: fotanus@gmail.com
29
57
  executables: []
@@ -32,8 +60,9 @@ extra_rdoc_files: []
32
60
  files:
33
61
  - ".gitignore"
34
62
  - ".rspec"
63
+ - ".travis.yml"
35
64
  - Gemfile
36
- - Gemfile.lock
65
+ - LICENSE.md
37
66
  - README.md
38
67
  - Rakefile
39
68
  - lib/xliffer.rb
data/Gemfile.lock DELETED
@@ -1,20 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- diff-lcs (1.2.5)
5
- nokogiri (1.5.9)
6
- rspec (2.99.0)
7
- rspec-core (~> 2.99.0)
8
- rspec-expectations (~> 2.99.0)
9
- rspec-mocks (~> 2.99.0)
10
- rspec-core (2.99.2)
11
- rspec-expectations (2.99.2)
12
- diff-lcs (>= 1.1.3, < 2.0)
13
- rspec-mocks (2.99.3)
14
-
15
- PLATFORMS
16
- ruby
17
-
18
- DEPENDENCIES
19
- nokogiri
20
- rspec (~> 2)