prawn-dev 0.3.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c4786b4cb0c1925fa2f5422e2a981e8dcb332ae60c955911653ddbad46b4f1f
4
- data.tar.gz: 9e590a9400bc77b10280a9e7c6692bce5eb913290cdcaa1bf948d0c5d2941ad1
3
+ metadata.gz: 59a3474b2e4134fb8a6ee6d9d8b319fe1f8163a0dc17da1829fb595210cbecb5
4
+ data.tar.gz: 3a8e7895c7d880136b8c5553f16a3fcde1c1d6e2b3b34f10c93ab1ac3e688b36
5
5
  SHA512:
6
- metadata.gz: 726543f165e577518f63da127ffe83b72cfcb956d56cd4979fde4e2b8a1beba1f11475e1d1e69c80e496f687e4c9e2d9ae258c8c67572f2fecfedcac14cb766b
7
- data.tar.gz: 26fed79a6f74bba1565131d9e556a85d7cde3fe6509d52aa3a00cd814d8871c89530bd49e26a41ace7b9163455b476b17a3545f9cfd8fac59f75bd1a8a370da6
6
+ metadata.gz: daf56294f1bde9d63c121ae4862273dd85bf26cea3e137f4047a85996529f65fa4c45dea7de42d9c2e8758eeea14f3a8aa526a67940ae91551281fa6b81709c1
7
+ data.tar.gz: f3eecf76613027b9815d1b9d5adf95cfe7acc9a2ca06189b71a1d0a4c5144029695b0567c12dd09692b106bc6a12589ff3838bbe1d23f6749002eb11a8146030
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'fileutils'
3
4
  require 'rubygems/package_task'
4
5
 
5
- unless Kernel.const_defined?('GEMSPEC')
6
+ unless Kernel.const_defined?(:GEMSPEC)
6
7
  raise StandardError, 'GEMSPEC is not defined'
7
8
  end
8
9
 
@@ -10,7 +11,7 @@ package_task = Gem::PackageTask.new(Gem::Specification.load(GEMSPEC))
10
11
  package_task.define
11
12
 
12
13
  built_gem_path = "pkg/#{package_task.package_name}.gem"
13
- checksum_path = "checksums/#{File.basename built_gem_path}.sha512"
14
+ checksum_path = "checksums/#{File.basename(built_gem_path)}.sha512"
14
15
 
15
16
  file built_gem_path do
16
17
  Rake::Task['package'].invoke
@@ -19,7 +20,7 @@ end
19
20
  file checksum_path => built_gem_path do
20
21
  require 'digest/sha2'
21
22
  checksum = Digest::SHA512.new.hexdigest(File.read(built_gem_path))
22
- Dir.mkdir('checksums') unless Dir.exist?('checksums')
23
+ FileUtils.mkdir_p('checksums')
23
24
  File.write(checksum_path, checksum)
24
25
  end
25
26
 
@@ -35,12 +36,50 @@ RSpec::Core::RakeTask.new('spec') do |c|
35
36
  end
36
37
 
37
38
  require 'yard'
39
+ YARD_OPTIONS = [
40
+ '--output-dir', 'doc/html',
41
+ '--verbose', '--debug',
42
+ '--load', File.expand_path('yard_markup.rb', __dir__),
43
+ '--markup', 'markdown',
44
+ '--markup-provider', 'prawn/dev/yard_markup/document',
45
+ '--use-cache',
46
+ ].freeze
38
47
 
39
48
  YARD::Rake::YardocTask.new do |t|
40
- t.options = ['--output-dir', 'doc/html']
49
+ t.options = YARD_OPTIONS + t.options
50
+ t.stats_options = ['--list-undoc', '--compact']
41
51
  end
42
52
  task docs: :yard
43
53
 
54
+ require 'fileutils'
55
+ def stash_yardopts
56
+ if File.exist?('.yardopts')
57
+ begin
58
+ original_opts = Shellwords.shellsplit(File.read('.yardopts'))
59
+ require('securerandom')
60
+ backup_file = ".yardopts-#{SecureRandom.alphanumeric(16)}.backup"
61
+ FileUtils.move('.yardopts', backup_file)
62
+ yield original_opts
63
+ ensure
64
+ FileUtils.move(backup_file, '.yardopts')
65
+ end
66
+ else
67
+ yield []
68
+ end
69
+ end
70
+
71
+ desc 'Generate YARD Documentation continuously'
72
+ task :yard_watch do
73
+ yard_server = YARD::CLI::Server.new
74
+ stash_yardopts do |original_opts|
75
+ File.open('.yardopts', 'w') do |yardopts|
76
+ yardopts.write((YARD_OPTIONS + original_opts).shelljoin)
77
+ yardopts.fsync
78
+ yard_server.run('--reload')
79
+ end
80
+ end
81
+ end
82
+
44
83
  require 'rubocop/rake_task'
45
84
 
46
85
  RuboCop::RakeTask.new
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Prawn
4
4
  module Dev
5
- VERSION = '0.3.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kramdown'
4
+ require 'rouge'
5
+
6
+ module Prawn
7
+ module Dev
8
+ module YardMarkup
9
+ module CodeHighlight
10
+ def html_syntax_highlight_ruby(source)
11
+ converter =
12
+ Kramdown::Converter::Html.__send__(
13
+ :new,
14
+ nil,
15
+ Prawn::Dev::YardMarkup::Document.new('').default_options,
16
+ )
17
+
18
+ el = Kramdown::Element.new(:codeblock, source, { lang: 'ruby' })
19
+ converter.convert(el, 0)
20
+ end
21
+ alias html_markup_ruby html_syntax_highlight_ruby
22
+
23
+ # Do nothing
24
+ def parse_codeblocks(html)
25
+ html
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kramdown'
4
+ require 'kramdown-parser-gfm'
5
+ require 'rouge'
6
+
7
+ module Prawn
8
+ module Dev
9
+ module YardMarkup
10
+ class CodeFormatter < ::Rouge::Formatter
11
+ def initialize(opts = {})
12
+ super
13
+
14
+ @opts = opts
15
+ @formatter =
16
+ if opts[:inline_theme]
17
+ ::Rouge::Formatters::HTMLInline.new(opts[:inline_theme])
18
+ else
19
+ ::Rouge::Formatters::HTML.new
20
+ end
21
+ end
22
+
23
+ def stream(tokens, &block)
24
+ yield %(<pre><code>) unless @opts[:inline]
25
+ @formatter.stream(tokens, &block)
26
+ yield '</code></pre>' unless @opts[:inline]
27
+ end
28
+ end
29
+
30
+ class Document < Kramdown::Document
31
+ def initialize(source, options = {})
32
+ super(source, default_options.merge(options))
33
+ end
34
+
35
+ def default_options
36
+ {
37
+ input: 'GFM',
38
+ hard_wrap: false,
39
+ syntax_highlighter: :rouge,
40
+ syntax_highlighter_opts: {
41
+ default_lang: 'ruby',
42
+ block: { formatter: CodeFormatter },
43
+ span: { formatter: CodeFormatter, inline: true },
44
+ },
45
+ }
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'yard_markup/code_highlight'
4
+
5
+ module Prawn
6
+ module Dev
7
+ module YardMarkup
8
+ YARD::Templates::Helpers::MarkupHelper::MARKUP_PROVIDERS[:markdown].push(
9
+ { lib: :'prawn/dev/yard_markup/document', const: 'Prawn::Dev::YardMarkup::Document' },
10
+ )
11
+ YARD::Templates::Engine.register_template_path(File.expand_path('../../../templates', __dir__))
12
+
13
+ YARD::Templates::Helpers::HtmlHelper.prepend(Prawn::Dev::YardMarkup::CodeHighlight)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Prawn
6
+ module Style
7
+ module TrailingCommaFix
8
+ def should_have_comma?(style, node)
9
+ if style == :prawn_comma
10
+ node.loc.begin.line != node.loc.end.line # parens are on different lines
11
+ else
12
+ super
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+ require_relative 'prawn/style/trailing_comma_fix'
5
+
6
+ RuboCop::Cop::Style::TrailingCommaInArguments.prepend(RuboCop::Cop::Prawn::Style::TrailingCommaFix)
7
+ RuboCop::Cop::Style::TrailingCommaInArrayLiteral.prepend(RuboCop::Cop::Prawn::Style::TrailingCommaFix)
8
+ RuboCop::Cop::Style::TrailingCommaInBlockArgs.prepend(RuboCop::Cop::Prawn::Style::TrailingCommaFix)
9
+ RuboCop::Cop::Style::TrailingCommaInHashLiteral.prepend(RuboCop::Cop::Prawn::Style::TrailingCommaFix)
10
+
11
+ %w[
12
+ Style/TrailingCommaInArguments
13
+ Style/TrailingCommaInArrayLiteral
14
+ Style/TrailingCommaInBlockArgs
15
+ Style/TrailingCommaInHashLiteral
16
+ ].each do |cop_name|
17
+ RuboCop::ConfigLoader.default_configuration[cop_name]['SupportedStylesForMultiline']&.append('prawn_comma')
18
+ end