concerto_simple_rss 0.0.9 → 0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27bcb6e184059a5cbae750cb4851cf0161e966e0
4
- data.tar.gz: ff9e1a3d2da810814ae11b4d1bbd8f9e89433ac2
3
+ metadata.gz: 5e6fb52c7e3495312e80894ac2eb676a17e35d24
4
+ data.tar.gz: 7c7cf3c32745e8f4f62e8ed0e09ea944fb228dbd
5
5
  SHA512:
6
- metadata.gz: 506c01f6444c666f2a5756f81c5a2c205382216a09ad5a7a9a57c3f28d326d32d06c76973e04cb0d14032a07952dc00a00cfb21eb5170daaa17aec17be2d8130
7
- data.tar.gz: 94afe471154677c38a7ef8af2205f91e2d62cb3ae1e8a5f4f6aa52f5fb23fcc05ef571d7497081067de1217a701e79a10c9fd985b7b0a3b7d67c4effb93c30d4
6
+ metadata.gz: a33d6fcaa6f01b09b975812216f2eb044137363d86543575a1bb18d244aee0c160129edf94b2485a2a2724a05e3daecf49abfa126621d95e0cec5622e04eee00
7
+ data.tar.gz: c687174d1b8677b00114db8d97f7277f718d8f58220c6ae819b4a487d1ceceb22a80f7ac5d24527c983d6a441c036b5156ac9a072589072ae8a34a5035f8c99d
@@ -38,14 +38,88 @@ class SimpleRss < DynamicContent
38
38
  require 'rexml/document'
39
39
  require 'xml/xslt'
40
40
 
41
- XML::XSLT.registerErrorHandler { |string| puts string }
41
+ #XML::XSLT.registerErrorHandler { |string| puts string }
42
42
  xslt = XML::XSLT.new()
43
- xslt.xml = REXML::Document.new(raw)
44
- xslt.xsl = REXML::Document.new(self.config['xsl'])
45
- htmltext = HtmlText.new()
46
- htmltext.name = "#{feed_title}"
47
- htmltext.data = xslt.serve()
48
- contents << htmltext
43
+ begin
44
+ xslt.xml = REXML::Document.new(raw)
45
+ rescue REXML::ParseException => e
46
+ Rails.logger.error("Unable to parse incoming feed: #{e.message}")
47
+ raise "Unable to parse incoming feed. "
48
+ rescue => e
49
+ raise e
50
+ end
51
+
52
+ begin
53
+ xslt.xsl = REXML::Document.new(self.config['xsl'])
54
+ rescue REXML::ParseException => e
55
+ Rails.logger.error("Unable to parse Xsl: #{e.message}")
56
+ # fmt is <rexml::parseexception: message :> trace ... so just pull out the message
57
+ s = e.message
58
+ msg_stop = s.index(">")
59
+ s = s.slice(23, msg_stop - 23) if !msg_stop.nil?
60
+ raise "Unable to parse Xsl. #{s}"
61
+ rescue => e
62
+ raise e
63
+ end
64
+
65
+ # add a replace [gsub] function for more powerful transforms. You can use this in a transform
66
+ # by adding the bogus namespace http://concerto.functions
67
+ # A nodeset comes in as an array of REXML::Elements
68
+ XML::XSLT.registerExtFunc("http://concerto.functions", "replace") do |nodes, pattern, replacement|
69
+ result = []
70
+ begin
71
+ # this will only work with nodesets for now
72
+ re_pattern = Regexp.new(pattern)
73
+ if nodes.is_a?(Array) && nodes.count > 0 && nodes.first.is_a?(REXML::Element)
74
+ nodes.each do |node|
75
+ s = node.to_s
76
+ r = s.gsub(re_pattern, replacement)
77
+ result << REXML::Document.new(r)
78
+ end
79
+ elsif nodes.is_a?(String)
80
+ result = nodes.gsub(re_pattern, replacement)
81
+ else
82
+ # dont know how to handle this
83
+ Rails.logger.info "I'm sorry, but the xsl external function replace does not know how to handle this type #{nodes.class}"
84
+ end
85
+ rescue
86
+ Rails.logger.error "there was a problem replacing #{pattern} with #{replacement}"
87
+ end
88
+
89
+ result
90
+ end
91
+
92
+ data = xslt.serve()
93
+
94
+ # try to load the transformed data as an xml document so we can see if there are
95
+ # mulitple content-items that we need to parse out, if we cant then treat it as one content item
96
+ begin
97
+ data_xml = REXML::Document.new('<root>' + data + '</root>')
98
+ nodes = REXML::XPath.match(data_xml, "//content-item")
99
+ # if there are no content-items then add the whole result (data) as one content
100
+ if nodes.count == 0
101
+ htmltext = HtmlText.new()
102
+ htmltext.name = "#{feed_title}"
103
+ htmltext.data = data
104
+ contents << htmltext
105
+ else
106
+ # if there are any content-items then add each one as a separate content
107
+ nodes.each do |n|
108
+ htmltext = HtmlText.new()
109
+ htmltext.name = "#{feed_title}"
110
+ htmltext.data = n.to_s
111
+ contents << htmltext
112
+ end
113
+ end
114
+ rescue => e
115
+ Rails.logger.error("unable to parse resultant xml, assuming it is one content item #{e.message}")
116
+ # raise "unable to parse resultant xml #{e.message}"
117
+ # add the whole result as one content
118
+ htmltext = HtmlText.new()
119
+ htmltext.name = "#{feed_title}"
120
+ htmltext.data = data
121
+ contents << htmltext
122
+ end
49
123
  else
50
124
  raise ArgumentError, 'Unexpected output format for RSS feed.'
51
125
  end
@@ -198,7 +272,7 @@ class SimpleRss < DynamicContent
198
272
  o.config['xsl'] = data[:xsl]
199
273
  results = o.build_content.first.data
200
274
  rescue => e
201
- results = "Unable to preview #{e.message}"
275
+ results = "Unable to preview. #{e.message}"
202
276
  end
203
277
 
204
278
  return results
@@ -1,3 +1,3 @@
1
1
  module ConcertoSimpleRss
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concerto_simple_rss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: '0.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Michalski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-07 00:00:00.000000000 Z
11
+ date: 2014-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  requirements: []
129
129
  rubyforge_project:
130
- rubygems_version: 2.0.3
130
+ rubygems_version: 2.0.14
131
131
  signing_key:
132
132
  specification_version: 4
133
133
  summary: RSS Dynamic Concerto for Concerto 2.