redmine_api_helper 0.3.35

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of redmine_api_helper might be problematic. Click here for more details.

Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +2 -0
  3. data/.gitignore +11 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/Gemfile +6 -0
  6. data/LICENSE +339 -0
  7. data/README.md +30 -0
  8. data/Rakefile +2 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/lib/date_helper/date.rb +311 -0
  12. data/lib/odf_writer/bookmark.rb +110 -0
  13. data/lib/odf_writer/bookmark_reader.rb +77 -0
  14. data/lib/odf_writer/document.rb +371 -0
  15. data/lib/odf_writer/field.rb +174 -0
  16. data/lib/odf_writer/field_reader.rb +78 -0
  17. data/lib/odf_writer/image.rb +176 -0
  18. data/lib/odf_writer/image_reader.rb +76 -0
  19. data/lib/odf_writer/images.rb +89 -0
  20. data/lib/odf_writer/list_style.rb +336 -0
  21. data/lib/odf_writer/nested.rb +156 -0
  22. data/lib/odf_writer/odf_helper.rb +57 -0
  23. data/lib/odf_writer/parser/default.rb +691 -0
  24. data/lib/odf_writer/path_finder.rb +114 -0
  25. data/lib/odf_writer/section.rb +120 -0
  26. data/lib/odf_writer/section_reader.rb +61 -0
  27. data/lib/odf_writer/style.rb +483 -0
  28. data/lib/odf_writer/table.rb +135 -0
  29. data/lib/odf_writer/table_reader.rb +61 -0
  30. data/lib/odf_writer/template.rb +234 -0
  31. data/lib/odf_writer/text.rb +97 -0
  32. data/lib/odf_writer/text_reader.rb +77 -0
  33. data/lib/odf_writer/version.rb +29 -0
  34. data/lib/redmine_api_helper/api_helper.rb +333 -0
  35. data/lib/redmine_api_helper/args_helper.rb +106 -0
  36. data/lib/redmine_api_helper/attachments_api_helper.rb +52 -0
  37. data/lib/redmine_api_helper/define_api_helpers.rb +78 -0
  38. data/lib/redmine_api_helper/document_categories_api_helper.rb +38 -0
  39. data/lib/redmine_api_helper/groups_api_helper.rb +80 -0
  40. data/lib/redmine_api_helper/helpers.rb +50 -0
  41. data/lib/redmine_api_helper/issue_priorities_api_helper.rb +38 -0
  42. data/lib/redmine_api_helper/issue_relations_api_helper.rb +66 -0
  43. data/lib/redmine_api_helper/issue_statuses_api_helper.rb +36 -0
  44. data/lib/redmine_api_helper/issues_api_helper.rb +124 -0
  45. data/lib/redmine_api_helper/my_account_api_helper.rb +45 -0
  46. data/lib/redmine_api_helper/news_api_helper.rb +73 -0
  47. data/lib/redmine_api_helper/project_memberships_api_helper.rb +77 -0
  48. data/lib/redmine_api_helper/projects_api_helper.rb +73 -0
  49. data/lib/redmine_api_helper/roles_api_helper.rb +52 -0
  50. data/lib/redmine_api_helper/scripts_api_helper.rb +87 -0
  51. data/lib/redmine_api_helper/search_api_helper.rb +38 -0
  52. data/lib/redmine_api_helper/time_entries_api_helper.rb +73 -0
  53. data/lib/redmine_api_helper/time_entry_activities_api_helper.rb +38 -0
  54. data/lib/redmine_api_helper/trackers_api_helper.rb +38 -0
  55. data/lib/redmine_api_helper/users_api_helper.rb +73 -0
  56. data/lib/redmine_api_helper/version.rb +24 -0
  57. data/lib/redmine_api_helper/wiki_pages_api_helper.rb +66 -0
  58. data/lib/redmine_api_helper.rb +88 -0
  59. data/redmine_api_helper.gemspec +36 -0
  60. metadata +162 -0
@@ -0,0 +1,234 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Ruby Gem to create a self populating Open Document Format (.odf) text file.
4
+ #
5
+ # Copyright 2021 Stephan Wenzel <stephan.wenzel@drwpatent.de>
6
+ #
7
+ # This program is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU General Public License
9
+ # as published by the Free Software Foundation; either version 2
10
+ # of the License, or (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
+ #
21
+
22
+ module ODFWriter
23
+
24
+ ########################################################################################
25
+ #
26
+ # Template: handles files in .odt-package
27
+ #
28
+ ########################################################################################
29
+ class Template
30
+
31
+ ######################################################################################
32
+ #
33
+ # constants - we only work and content and styles (contains headers and footers) parts of odf
34
+ #
35
+ ######################################################################################
36
+ CONTENT_ENTRIES = {
37
+ "content.xml" => {:symbol => :content, :path => "content.xml"},
38
+ "styles.xml" => {:symbol => :styles, :path => "styles.xml" }
39
+ }.freeze
40
+
41
+ CONTENT_FILES = {
42
+ :content => {:file => "content.xml", :path => "content.xml"},
43
+ :styles => {:file => "styles.xml", :path => "styles.xml" }
44
+ }.freeze
45
+
46
+ MANIFEST = 'META-INF/manifest.xml'.freeze
47
+
48
+ ######################################################################################
49
+ #
50
+ # accessors
51
+ #
52
+ ######################################################################################
53
+ attr_accessor :output_stream
54
+
55
+ ######################################################################################
56
+ #
57
+ # initialize
58
+ #
59
+ ######################################################################################
60
+ def initialize(path = nil, zip_stream: nil)
61
+
62
+ raise "You must provide either a filename or a zip_stream: string" unless path || zip_stream
63
+ raise "Template [#{template}] not found." if path && !::File.exist?(path)
64
+
65
+ @path = path
66
+ @zip_stream = zip_stream
67
+ end #def
68
+
69
+ ######################################################################################
70
+ #
71
+ # content
72
+ #
73
+ ######################################################################################
74
+ def content(&block)
75
+
76
+ entries.each do |entry|
77
+
78
+ if entry.directory?
79
+ next
80
+
81
+ elsif CONTENT_ENTRIES.keys.include?(entry.name)
82
+ # relevant file with valid file name
83
+ entry.get_input_stream do |input_stream|
84
+ file_content = input_stream.sysread
85
+ yield CONTENT_ENTRIES[entry.name][:symbol], to_xml(file_content)
86
+ end
87
+
88
+ end #if
89
+ end #each
90
+ end #def
91
+
92
+ ######################################################################################
93
+ #
94
+ # update_content: create write buffer for zip
95
+ #
96
+ ######################################################################################
97
+ def update_content
98
+ @buffer = Zip::OutputStream.write_buffer do |out|
99
+ @output_stream = out
100
+ yield self
101
+ end
102
+ end
103
+
104
+ ######################################################################################
105
+ #
106
+ # update_files: open and traverse zip directory, pick content.xml
107
+ # and styles.xml process and eventually write contents
108
+ # to buffer
109
+ # a pointer to manifest.xml is provided
110
+ #
111
+ ######################################################################################
112
+ def update_files(&block)
113
+
114
+ # get manifest, in case a file is added
115
+ # @manifest = manifest; digest = Digest::MD5.hexdigest(@manifest)
116
+ @manifest = manifest
117
+
118
+ # the very first entry must be a file named "mimetype", not compressed
119
+ #mimetype = ::Zip::Entry.new("out.zip", "mimetype")
120
+ # file attribute 0 means binary file
121
+ #mimetype.internal_file_attributes = 0
122
+ #mimetype.compression_method = ::Zip::COMPRESSION_METHOD_STORE
123
+ #@output_stream.put_next_entry(mimetype)
124
+ @output_stream.put_next_entry("mimetype", nil, nil, ::Zip::COMPRESSION_METHOD_STORE)
125
+ @output_stream.write "application/vnd.oasis.opendocument.text"
126
+
127
+ entries.each do |entry|
128
+
129
+ next if entry.directory?
130
+ next if entry.name == "mimetype" # neglect possible other mimetype files
131
+ next if entry.name == MANIFEST
132
+
133
+ # process content files
134
+ if CONTENT_ENTRIES.keys.include?(entry.name)
135
+
136
+ entry.get_input_stream do |input_stream|
137
+ file_content = input_stream.sysread
138
+ file_symbol = CONTENT_ENTRIES[entry.name][:symbol]
139
+ # process entry, if files are added, then @mainfest is changed
140
+ process_entry(file_symbol, file_content, @manifest, &block)
141
+
142
+ @output_stream.put_next_entry(entry.name)
143
+ @output_stream.write file_content
144
+ end #do
145
+
146
+ else
147
+ entry.get_input_stream do |input_stream|
148
+ @output_stream.put_next_entry(entry.name)
149
+ @output_stream.write input_stream.sysread
150
+ end
151
+ end #if
152
+ end #each
153
+
154
+ # eventually write back content file
155
+ #if @manifest && digest != Digest::MD5.hexdigest(@manifest)
156
+ @output_stream.put_next_entry(MANIFEST)
157
+ @output_stream.write @manifest
158
+ #end #if
159
+
160
+ end #def
161
+
162
+
163
+ ######################################################################################
164
+ #
165
+ # data: just a handle to data in buffer
166
+ #
167
+ ######################################################################################
168
+ def data
169
+ @buffer.string
170
+ end
171
+
172
+ ######################################################################################
173
+ #
174
+ # private
175
+ #
176
+ ######################################################################################
177
+ private
178
+
179
+ ######################################################################################
180
+ # entries: just open zip file or buffer
181
+ ######################################################################################
182
+ def entries
183
+ if @path
184
+ Zip::File.open(@path)
185
+ elsif @zip_stream
186
+ Zip::File.open_buffer(@zip_stream.force_encoding("ASCII-8BIT"))
187
+ end
188
+ end #def
189
+
190
+ ######################################################################################
191
+ # manifest: read manifest
192
+ ######################################################################################
193
+ def manifest
194
+ manifest = nil
195
+ entries.each do |entry|
196
+ next if entry.directory?
197
+ if entry.name == MANIFEST
198
+ entry.get_input_stream do |input_stream|
199
+ manifest = input_stream.sysread.dup
200
+ end
201
+ end
202
+ end
203
+ manifest
204
+ end #def
205
+
206
+ ######################################################################################
207
+ # to_xml
208
+ ######################################################################################
209
+ def to_xml(raw_xml)
210
+ Nokogiri::XML(raw_xml)
211
+ end #def
212
+
213
+ ######################################################################################
214
+ # process_entry: provide Nokogiri Object to caller, after having provided a file
215
+ ######################################################################################
216
+ def process_entry(file_symbol, file_content, manifest)
217
+
218
+ # create xml from file content
219
+ doc = to_xml(file_content ) # { |x| x.noblanks }
220
+ man = to_xml(manifest ) # { |x| x.noblanks }
221
+
222
+ # yield xml
223
+ yield file_symbol, doc, man
224
+
225
+ # replace file_content and manifest in place
226
+ # remove spurious whitespaces between tags "> <" becomes "><"
227
+ file_content.replace(doc.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML).squish.gsub(/(?<=>)\s+(?=<)/, "") + "\r\n")
228
+ # Microsoft Words complains if no trailing newline is present
229
+ manifest.replace(man.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML) + "\r\n")
230
+
231
+ end #def
232
+
233
+ end #class
234
+ end #module
@@ -0,0 +1,97 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Ruby Gem to create a self populating Open Document Format (.odf) text file.
4
+ #
5
+ # Copyright 2021 Stephan Wenzel <stephan.wenzel@drwpatent.de>
6
+ #
7
+ # This program is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU General Public License
9
+ # as published by the Free Software Foundation; either version 2
10
+ # of the License, or (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
+ #
21
+
22
+ module ODFWriter
23
+
24
+ ########################################################################################
25
+ #
26
+ # Text: replace text items
27
+ #
28
+ ########################################################################################
29
+ class Text < Field
30
+
31
+ ######################################################################################
32
+ #
33
+ # constants
34
+ #
35
+ ######################################################################################
36
+ DELIMITERS = %w({ })
37
+
38
+ ######################################################################################
39
+ #
40
+ # replace!
41
+ #
42
+ ######################################################################################
43
+ def replace!(content, item = nil)
44
+
45
+ return unless node = find_text_node(content)
46
+
47
+ text = value(item)
48
+
49
+ @parser = Parser::Default.new(text, node,
50
+ :doc => content,
51
+ :remove_classes => @remove_classes,
52
+ :remove_class_prefix => @remove_class_prefix,
53
+ :remove_class_suffix => @remove_class_suffix
54
+ )
55
+
56
+ @parser.paragraphs.each do |p|
57
+ node.before(p)
58
+ end
59
+
60
+ node.remove
61
+
62
+ end #def
63
+
64
+ ######################################################################################
65
+ #
66
+ # private
67
+ #
68
+ ######################################################################################
69
+ private
70
+
71
+ ######################################################################################
72
+ # find_text_node
73
+ ######################################################################################
74
+ def find_text_node(doc)
75
+ texts = doc.xpath(".//text:p[text()='#{placeholder}']")
76
+ if texts.empty?
77
+ texts = doc.xpath(".//text:p/text:span[text()='#{placeholder}']")
78
+ if texts.empty?
79
+ texts = nil
80
+ else
81
+ texts = texts.first.parent
82
+ end
83
+ else
84
+ texts = texts.first
85
+ end
86
+
87
+ texts
88
+ end #def
89
+
90
+ ######################################################################################
91
+ # placeholder
92
+ ######################################################################################
93
+ def placeholder
94
+ "#{DELIMITERS[0]}#{@name.to_s.upcase}#{DELIMITERS[1]}"
95
+ end #def
96
+ end #class
97
+ end #module
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Ruby Gem to create a self populating Open Document Format (.odf) text file.
4
+ #
5
+ # Copyright 2021 Stephan Wenzel <stephan.wenzel@drwpatent.de>
6
+ #
7
+ # This program is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU General Public License
9
+ # as published by the Free Software Foundation; either version 2
10
+ # of the License, or (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
+ #
21
+
22
+ module ODFWriter
23
+
24
+ ########################################################################################
25
+ #
26
+ # TextReader: find all texts and set name
27
+ #
28
+ ########################################################################################
29
+ class TextReader < FieldReader
30
+
31
+ attr_accessor :name
32
+
33
+ ######################################################################################
34
+ #
35
+ # initialize
36
+ #
37
+ ######################################################################################
38
+ def initialize(opts={})
39
+ @name = opts[:name]
40
+ end #def
41
+
42
+ ######################################################################################
43
+ #
44
+ # paths
45
+ #
46
+ ######################################################################################
47
+ def paths( file, doc)
48
+
49
+ # find nodes with matching field elements matching [FIELD] pattern
50
+ nodes = doc.xpath("//text()").select{|node| scan(node).present? }
51
+
52
+ # find path for each field
53
+ paths = nil
54
+ nodes.each do |node|
55
+ leaf = {:texts => scan(node)}
56
+ paths = PathFinder.trail(node, leaf, :root => file, :paths => paths)
57
+ end #each
58
+ paths.to_h
59
+
60
+ end #def
61
+
62
+ ######################################################################################
63
+ # private
64
+ ######################################################################################
65
+
66
+ private
67
+
68
+ def scan(node)
69
+ if name
70
+ node.text.scan(/(?<=#{Regexp.escape Text::DELIMITERS[0]})#{name.upcase}(?=#{Regexp.escape Text::DELIMITERS[1]})/)
71
+ else
72
+ node.text.scan(/(?<=#{Regexp.escape Text::DELIMITERS[0]})[A-Z0-9_]+?(?=#{Regexp.escape Text::DELIMITERS[1]})/)
73
+ end
74
+ end #def
75
+
76
+ end #class
77
+ end #module
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Ruby Gem to create a self populating Open Document Format (.odf) text file.
4
+ #
5
+ # Copyright 2021 Stephan Wenzel <stephan.wenzel@drwpatent.de>
6
+ #
7
+ # This program is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU General Public License
9
+ # as published by the Free Software Foundation; either version 2
10
+ # of the License, or (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
+ #
21
+
22
+ module ODFWriter
23
+ # 1.0.2
24
+ # - added arrify to document.rb
25
+ #
26
+ # 1.0.1 initial commit
27
+ #
28
+ VERSION = "1.0.13"
29
+ end #module