prawn-dev 0.3.0 → 0.4.0

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: 8c4786b4cb0c1925fa2f5422e2a981e8dcb332ae60c955911653ddbad46b4f1f
4
- data.tar.gz: 9e590a9400bc77b10280a9e7c6692bce5eb913290cdcaa1bf948d0c5d2941ad1
3
+ metadata.gz: 0e001fdf15ba461fb80cf6bf5c552b387d35b38bfdaf1f7b452242bbcf8aa8a3
4
+ data.tar.gz: 840114726af26d000ee361e1a889abbcf29a99f4cd266ffbda04d1db6ac4ff38
5
5
  SHA512:
6
- metadata.gz: 726543f165e577518f63da127ffe83b72cfcb956d56cd4979fde4e2b8a1beba1f11475e1d1e69c80e496f687e4c9e2d9ae258c8c67572f2fecfedcac14cb766b
7
- data.tar.gz: 26fed79a6f74bba1565131d9e556a85d7cde3fe6509d52aa3a00cd814d8871c89530bd49e26a41ace7b9163455b476b17a3545f9cfd8fac59f75bd1a8a370da6
6
+ metadata.gz: 28370a98a9791b0dfa6fb7985ad97f6d9d66646863a926a64348407b2f6db2b9998ad0249ca53699fe6221d7a7028d2f99942797c62a91c837d107fd0f245627
7
+ data.tar.gz: 60276b7b8db038441c2268fdf26cc04ef5bc14bea4b21a3178f1eaacd8d0e0d3a67aabd90d286c27e0b2fa90551abecffc6d79cba1440194a052e661ff3d647f
checksums.yaml.gz.sig CHANGED
Binary file
@@ -35,12 +35,50 @@ RSpec::Core::RakeTask.new('spec') do |c|
35
35
  end
36
36
 
37
37
  require 'yard'
38
+ YARD_OPTIONS = [
39
+ '--output-dir', 'doc/html',
40
+ '--verbose', '--debug',
41
+ '--load', File.expand_path('yard_markup.rb', __dir__),
42
+ '--markup', 'markdown',
43
+ '--markup-provider', 'prawn/dev/yard_markup/document',
44
+ '--use-cache',
45
+ ]
38
46
 
39
47
  YARD::Rake::YardocTask.new do |t|
40
- t.options = ['--output-dir', 'doc/html']
48
+ t.options = YARD_OPTIONS + t.options
49
+ t.stats_options = ['--list-undoc', '--compact']
41
50
  end
42
51
  task docs: :yard
43
52
 
53
+ require 'fileutils'
54
+ def stash_yardopts
55
+ if File.exist?('.yardopts')
56
+ begin
57
+ original_opts = Shellwords.shellsplit File.read('.yardopts')
58
+ require('securerandom')
59
+ backup_file = ".yardopts-#{SecureRandom.alphanumeric(16)}.backup"
60
+ FileUtils.move('.yardopts', backup_file)
61
+ yield original_opts
62
+ ensure
63
+ FileUtils.move(backup_file, '.yardopts')
64
+ end
65
+ else
66
+ yield []
67
+ end
68
+ end
69
+
70
+ desc 'Generate YARD Documentation continuously'
71
+ task :yard_watch do
72
+ yard_server = YARD::CLI::Server.new
73
+ stash_yardopts do |original_opts|
74
+ File.open('.yardopts', 'w') do |yardopts|
75
+ yardopts.write((YARD_OPTIONS + original_opts).shelljoin)
76
+ yardopts.fsync
77
+ yard_server.run('--reload')
78
+ end
79
+ end
80
+ end
81
+
44
82
  require 'rubocop/rake_task'
45
83
 
46
84
  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.4.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,48 @@
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
+ @opts = opts
13
+ @formatter =
14
+ if opts[:inline_theme]
15
+ ::Rouge::Formatters::HTMLInline.new(opts[:inline_theme])
16
+ else
17
+ ::Rouge::Formatters::HTML.new
18
+ end
19
+ end
20
+
21
+ def stream(tokens, &block)
22
+ yield %(<pre><code>) unless @opts[:inline]
23
+ @formatter.stream(tokens, &block)
24
+ yield '</code></pre>' unless @opts[:inline]
25
+ end
26
+ end
27
+
28
+ class Document < Kramdown::Document
29
+ def initialize(source, options = {})
30
+ super(source, default_options.merge(options))
31
+ end
32
+
33
+ def default_options
34
+ {
35
+ input: 'GFM',
36
+ hard_wrap: false,
37
+ syntax_highlighter: :rouge,
38
+ syntax_highlighter_opts: {
39
+ default_lang: 'ruby',
40
+ block: { formatter: CodeFormatter },
41
+ span: { formatter: CodeFormatter, inline: true },
42
+ },
43
+ }
44
+ end
45
+ end
46
+ end
47
+ end
48
+ 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