newsman 0.1.8 → 0.1.9

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
  SHA256:
3
- metadata.gz: 6003cd186c9fc0dc4db267e6c51aecddbf3b1c5de58c63331efc985f3c99f996
4
- data.tar.gz: 1255f0f57387649a4ffa9bac8c3e726f6f3e6e37fbd67fef022c17121c297f53
3
+ metadata.gz: 2394e606a441d219f1b63d81957596975476de4da4a8cf2a8565638d9e5fd31e
4
+ data.tar.gz: 10c89c9e91a89fde8c67822d72ada6de3cf731b1c3a7fc9aa9d0e7ad90c1f43a
5
5
  SHA512:
6
- metadata.gz: dd1258731d17b2df35dd46bd2e74c5b22881fed9370c97430c2246db3a879f8dd7289b07f1fb36429ad3e9ed0320e7b886504ebe0a2b734461a18f702551be04
7
- data.tar.gz: 70be6d66ebcc920367f1143212c14ed00feb14f2653c514b7a58e6a8e1b939a3d945d4990888a8264a9224d20cd39717e6bddb0c0d0baa6361c8f8243621fac8
6
+ metadata.gz: d649675bf107b488ce5c8644414589419518e9f8f8ea497d80da5a3810de6fecc1a1f346fbd4c06a84f41e979df890af50ec89bbc89ed34056af5b7467f40dce
7
+ data.tar.gz: 7de3191d99baee21f3346434d6aeb6550e9bb07e8f9a944215958206cd94a1176f367f699b84778a063227a165bf4e065bccbe48def5e8d9b1ae33eb6a59d2fc
@@ -0,0 +1,45 @@
1
+ require 'erb'
2
+ # frozen_string_literal: true
3
+
4
+ class Htmlout
5
+
6
+ TEMPLATE = "<!DOCTYPE html>
7
+ <html lang=\"en\">
8
+ <head>
9
+ <meta charset=\"UTF-8\">
10
+ <title><%= title %></title>
11
+ </head>
12
+ <body>
13
+ <h1><%= title %></h1>
14
+ <p><%= body %></p>
15
+ </body>
16
+ </html>
17
+ "
18
+
19
+ def initialize(root = '.')
20
+ @root = root
21
+ end
22
+
23
+ def print(report, reporter)
24
+ title = title(reporter)
25
+ body = report
26
+ renderer = ERB.new(TEMPLATE)
27
+ html_content = renderer.result(binding)
28
+ puts "Create a html file in a directory #{@root}"
29
+ file = File.new(File.join(@root, filename(reporter)), 'w')
30
+ puts "File #{file.path} was successfully created"
31
+ file.puts html_content
32
+ puts "Report was successfully printed to a #{file.path}"
33
+ file.close
34
+ end
35
+
36
+ def title(reporter)
37
+ date = Time.new.strftime('%d.%m.%Y')
38
+ "#{reporter} #{date}"
39
+ end
40
+
41
+ def filename(reporter)
42
+ date = Time.new.strftime('%d.%m.%Y')
43
+ "#{date}.#{reporter}.html"
44
+ end
45
+ end
data/lib/newsman.rb CHANGED
@@ -9,6 +9,7 @@ require_relative 'newsman/pull_request'
9
9
  require_relative 'newsman/issues'
10
10
  require_relative 'newsman/stdout_output'
11
11
  require_relative 'newsman/txt_output'
12
+ require_relative 'newsman/html_output'
12
13
  require_relative 'newsman/report'
13
14
 
14
15
  def generate
@@ -32,7 +33,7 @@ def generate
32
33
  options[:position] = p
33
34
  end
34
35
  opts.on('-o', '--output OUTPUT',
35
- "Output type. Newsman prints a report to a stdout by default. You can choose another options like '-o html' or '-o txt'") do |o|
36
+ "Output type. Newsman prints a report to a stdout by default. You can choose another options like '-o html', '-o txt' or even '-o html'") do |o|
36
37
  options[:output] = o
37
38
  end
38
39
  opts.on('-t', '--title TITLE', 'Project Title. Empty by default') do |t|
@@ -160,9 +161,15 @@ def generate
160
161
  puts "Output mode is '#{output_mode}'"
161
162
  full_answer = Report.new(reporter, reporter_position, options[:title]).build(answer, issues_full_answer, Date.today)
162
163
  if output_mode.eql? 'txt'
164
+ puts "Print result to txy file"
163
165
  output = Txtout.new('.')
164
166
  output.print(full_answer, github_username)
167
+ elsif output_mode.eql? 'html'
168
+ puts "Print result to html file"
169
+ output = Htmlout.new('.')
170
+ output.print(full_answer, github_username)
165
171
  else
172
+ puts "Print result to stdout"
166
173
  output = Stdout.new
167
174
  output.print(full_answer)
168
175
  end
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Copyright (c) 2024 Volodya Lombrozo
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'minitest/autorun'
25
+ require_relative '../lib/newsman/html_output'
26
+
27
+ class TestHtmlout < Minitest::Test
28
+
29
+ EXPECTED = "<!DOCTYPE html>
30
+ <html lang=\"en\">
31
+ <head>
32
+ <meta charset=\"UTF-8\">
33
+ <title>volodya-lombrozo #{Time.new.strftime('%d.%m.%Y')}</title>
34
+ </head>
35
+ <body>
36
+ <h1>volodya-lombrozo #{Time.new.strftime('%d.%m.%Y')}</h1>
37
+ <p>Issue description</p>
38
+ </body>
39
+ </html>
40
+ "
41
+
42
+ def test_writes_to_a_html_file
43
+ Dir.mktmpdir do |temp_dir|
44
+ output = Htmlout.new(temp_dir)
45
+ today = Date.today.strftime('%d.%m.%Y')
46
+ expected = "#{today}.volodya-lombrozo.html"
47
+ output.print("Issue description", 'volodya-lombrozo')
48
+ assert(File.exist?(File.join(temp_dir, expected)))
49
+ assert_equal(EXPECTED, File.read(File.join(temp_dir, expected)))
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newsman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volodya Lombrozo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-01 00:00:00.000000000 Z
11
+ date: 2024-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -135,11 +135,13 @@ files:
135
135
  - README.md
136
136
  - bin/newsman
137
137
  - lib/newsman.rb
138
+ - lib/newsman/html_output.rb
138
139
  - lib/newsman/issues.rb
139
140
  - lib/newsman/pull_request.rb
140
141
  - lib/newsman/report.rb
141
142
  - lib/newsman/stdout_output.rb
142
143
  - lib/newsman/txt_output.rb
144
+ - test/test_htmlout.rb
143
145
  - test/test_pdd_issue.rb
144
146
  - test/test_report.rb
145
147
  - test/test_txtout.rb
@@ -165,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
167
  - !ruby/object:Gem::Version
166
168
  version: '0'
167
169
  requirements: []
168
- rubygems_version: 3.5.6
170
+ rubygems_version: 3.5.7
169
171
  signing_key:
170
172
  specification_version: 4
171
173
  summary: GitHub user weekly news