icl 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +27 -0
- data/README.rdoc +4 -0
- data/Rakefile +9 -0
- data/bin/icl +42 -0
- data/icl.gemspec +20 -0
- data/lib/icl.rb +23 -0
- data/lib/icl/version.rb +3 -0
- data/pkg/icl-0.0.1.gem +0 -0
- data/pkg/icl-1.0.0.gem +0 -0
- data/test/icl_test.rb +80 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 675907eee35418109bffc64c47c362efb0a8bab703f09f61058d16aff30b76d5
|
4
|
+
data.tar.gz: '039e577e82567f1fb9f11aaaf195ff921080fc1c0009e87487fa0d8535a881c1'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dc0ef5172405af7b1ab1391f1f3e253d03e3664548c01da1b8fb10721f571318a490fa563a4fdb2e122945ad3ed75ad17a2e5ecd5e8194f0572fa7a3e32c1bd4
|
7
|
+
data.tar.gz: edc09f3b5456581969e7ebd29c62cc188b3aa4f12b484a9ab35b763e110f3837260e901a8a65f6c5b71f4b300098fa54e313dc0369161808b14ede5c83890bcc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
icl (1.0.0)
|
5
|
+
gli (= 2.19.0)
|
6
|
+
nokogiri
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
gli (2.19.0)
|
12
|
+
mini_portile2 (2.4.0)
|
13
|
+
minitest (5.14.0)
|
14
|
+
nokogiri (1.10.7)
|
15
|
+
mini_portile2 (~> 2.4.0)
|
16
|
+
rake (12.3.2)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
icl!
|
23
|
+
minitest
|
24
|
+
rake
|
25
|
+
|
26
|
+
BUNDLED WITH
|
27
|
+
2.0.1
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
data/bin/icl
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'gli'
|
3
|
+
require 'icl'
|
4
|
+
|
5
|
+
class App
|
6
|
+
extend GLI::App
|
7
|
+
|
8
|
+
program_desc 'A command line app for transforming XML documents'
|
9
|
+
|
10
|
+
version Icl::VERSION
|
11
|
+
|
12
|
+
desc 'Transforms an XML document using one or more XSLT stylesheets'
|
13
|
+
arg_name 'Name of the document type'
|
14
|
+
command :transform do |c|
|
15
|
+
c.action do |global_options,options,args|
|
16
|
+
Icl.transform(*args)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
pre do |global,command,options,args|
|
21
|
+
# Pre logic here
|
22
|
+
# Return true to proceed; false to abort and not call the
|
23
|
+
# chosen command
|
24
|
+
# Use skips_pre before a command to skip this block
|
25
|
+
# on that command only
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
post do |global,command,options,args|
|
30
|
+
# Post logic here
|
31
|
+
# Use skips_post before a command to skip this
|
32
|
+
# block on that command only
|
33
|
+
end
|
34
|
+
|
35
|
+
on_error do |exception|
|
36
|
+
# Error logic here
|
37
|
+
# return false to skip default error handling
|
38
|
+
true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
exit App.run(ARGV)
|
data/icl.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Ensure we require the local version and not one we might have installed already
|
2
|
+
require File.join([File.dirname(__FILE__),'lib','icl','version.rb'])
|
3
|
+
spec = Gem::Specification.new do |s|
|
4
|
+
s.name = 'icl'
|
5
|
+
s.version = Icl::VERSION
|
6
|
+
s.author = 'Andrew'
|
7
|
+
s.email = 'your@email.address.com'
|
8
|
+
s.homepage = 'http://your.website.com'
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.summary = 'A command line app for transforming XML documents.'
|
11
|
+
s.files = `git ls-files`.split("
|
12
|
+
")
|
13
|
+
s.require_paths << 'lib'
|
14
|
+
s.bindir = 'bin'
|
15
|
+
s.executables << 'icl'
|
16
|
+
s.add_development_dependency('rake')
|
17
|
+
s.add_development_dependency('minitest')
|
18
|
+
s.add_runtime_dependency('gli','2.19.0')
|
19
|
+
s.add_runtime_dependency('nokogiri')
|
20
|
+
end
|
data/lib/icl.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'icl/version.rb'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module Icl
|
5
|
+
def self.transform(xml_file, *stylesheet_files)
|
6
|
+
xml_string = File.open("#{xml_file}")
|
7
|
+
stylesheet_strings = stylesheet_files.map { |stylesheet_file| File.open("#{stylesheet_file}") }
|
8
|
+
|
9
|
+
puts transform_from_strings(xml_string, *stylesheet_strings)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.transform_from_strings(xml_string, *stylesheet_strings)
|
13
|
+
xml = Nokogiri::XML(xml_string)
|
14
|
+
output = xml
|
15
|
+
|
16
|
+
stylesheet_strings.each do |stylesheet_string|
|
17
|
+
stylesheet = Nokogiri::XSLT(stylesheet_string)
|
18
|
+
output = stylesheet.transform(output)
|
19
|
+
end
|
20
|
+
|
21
|
+
output
|
22
|
+
end
|
23
|
+
end
|
data/lib/icl/version.rb
ADDED
data/pkg/icl-0.0.1.gem
ADDED
Binary file
|
data/pkg/icl-1.0.0.gem
ADDED
Binary file
|
data/test/icl_test.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require_relative '../lib/icl.rb'
|
2
|
+
require "minitest/autorun"
|
3
|
+
|
4
|
+
class IclTest < Minitest::Test
|
5
|
+
def test_transform_an_xml_using_one_stylesheet
|
6
|
+
xml = <<~XML
|
7
|
+
<?xml version="1.0"?>
|
8
|
+
<name>
|
9
|
+
<title>Dr.</title>
|
10
|
+
<first>John</first>
|
11
|
+
<last>Smith</last>
|
12
|
+
</name>
|
13
|
+
XML
|
14
|
+
|
15
|
+
stylesheet = <<~XSLT
|
16
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
17
|
+
|
18
|
+
<xsl:template match="name">
|
19
|
+
<name>
|
20
|
+
<xsl:copy-of select="title"/>
|
21
|
+
<full><xsl:value-of select="concat(first, ' ', last)"/></full>
|
22
|
+
</name>
|
23
|
+
</xsl:template>
|
24
|
+
|
25
|
+
</xsl:stylesheet>
|
26
|
+
XSLT
|
27
|
+
|
28
|
+
output = <<~XML
|
29
|
+
<?xml version="1.0"?>
|
30
|
+
<name>
|
31
|
+
<title>Dr.</title>
|
32
|
+
<full>John Smith</full>
|
33
|
+
</name>
|
34
|
+
XML
|
35
|
+
|
36
|
+
assert_equal output, Icl.transform_from_strings(xml, stylesheet).to_s
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_transform_an_xml_using_multiple_transforms
|
40
|
+
xml = <<~XML
|
41
|
+
<?xml version="1.0"?>
|
42
|
+
<name>
|
43
|
+
<title>Dr.</title>
|
44
|
+
<first>John</first>
|
45
|
+
<last>Smith</last>
|
46
|
+
</name>
|
47
|
+
XML
|
48
|
+
|
49
|
+
stylesheet_1 = <<~XSLT
|
50
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
51
|
+
|
52
|
+
<xsl:template match="name">
|
53
|
+
<name>
|
54
|
+
<full><xsl:value-of select="concat(first, ' ', last)"/></full>
|
55
|
+
<xsl:copy-of select="title"/>
|
56
|
+
</name>
|
57
|
+
</xsl:template>
|
58
|
+
|
59
|
+
</xsl:stylesheet>
|
60
|
+
XSLT
|
61
|
+
|
62
|
+
|
63
|
+
stylesheet_2 = <<~XSLT
|
64
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
65
|
+
|
66
|
+
<xsl:template match="name">
|
67
|
+
<name><xsl:value-of select="concat(title, ' ', full)"/></name>
|
68
|
+
</xsl:template>
|
69
|
+
|
70
|
+
</xsl:stylesheet>
|
71
|
+
XSLT
|
72
|
+
|
73
|
+
output = <<~XML
|
74
|
+
<?xml version="1.0"?>
|
75
|
+
<name>Dr. John Smith</name>
|
76
|
+
XML
|
77
|
+
|
78
|
+
assert_equal output, Icl.transform_from_strings(xml, stylesheet_1, stylesheet_2).to_s
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: icl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: gli
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.19.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.19.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email: your@email.address.com
|
71
|
+
executables:
|
72
|
+
- icl
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- Gemfile
|
77
|
+
- Gemfile.lock
|
78
|
+
- README.rdoc
|
79
|
+
- Rakefile
|
80
|
+
- bin/icl
|
81
|
+
- icl.gemspec
|
82
|
+
- lib/icl.rb
|
83
|
+
- lib/icl/version.rb
|
84
|
+
- pkg/icl-0.0.1.gem
|
85
|
+
- pkg/icl-1.0.0.gem
|
86
|
+
- test/icl_test.rb
|
87
|
+
homepage: http://your.website.com
|
88
|
+
licenses: []
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.7.8
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: A command line app for transforming XML documents.
|
111
|
+
test_files: []
|