-
Notifications
You must be signed in to change notification settings - Fork 21
/
block.rb
71 lines (64 loc) · 2.84 KB
/
block.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class Block
# a recursive list of blocks that need to be processed before this block
attr_accessor :inputs
# a list of blocks that need to be processed before this block, that fill options.userinputs
attr_accessor :textinputs
# a hash with the options that change the behaviour of the block
attr_accessor :options
# the block id as generated in the editor (careful, user can manipulate that easily)
attr_accessor :id
# pipe object, used to inquire about user and meta data like the pipe title
attr_accessor :pipe
def initialize
self.inputs = []
self.options = {}
end
# get the pipe by calling the children, which means its output will be ready
# for our process function, which uses it as input
def run
processedInputs = []
inputs.each {|input| processedInputs << input&.run }
# here we override the userinput with the content of the textinput block, as those have priority
textinputs&.each_with_index do |textinput, i|
textinput = textinput&.run
options[:userinputs][i] = textinput if textinput
end
return self.process(processedInputs)
end
# the core function that manipulates the inputs
def process(inputs)
return inputs[0] # the root node will have only one child, and only has to echo it
end
# Transfer data from the old feedparser item of an input feed to the new regular rss item of the output feed
def transferData(newItem, oldItem)
newItem.title = oldItem.title
if oldItem.updated
newItem.updated = oldItem.updated.to_s
end
newItem.pubDate = oldItem.published.to_s if oldItem.published
if (oldItem.url && oldItem.url != '')
newItem.link = oldItem.url
else
newItem.link = '' # the rss won't get emitted if description is empty
end
newItem.content_encoded = oldItem.content
newItem.guid.content = oldItem.guid
newItem.guid.isPermaLink = oldItem.guid.include?('http')
newItem.description = oldItem.summary if oldItem.summary && ! oldItem.summary.empty?
newItem.author = oldItem.author if oldItem.author
if oldItem.attachments?
newItem.enclosure.url = oldItem.attachment.url
newItem.enclosure.length = oldItem.attachment.length
newItem.enclosure.type = oldItem.attachment.type
if (newItem.description.nil? || newItem.description.empty?) && oldItem.attachment.description
newItem.description = oldItem.attachment.description.gsub(/\n/,"<br />\n")
end
end
oldItem.categories.each do |category|
target = newItem.categories.new_category
target.content = category.name
target.domain = category.scheme
end
return newItem
end
end