prawn-manual_builder 0.3.0 → 0.3.1

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
- SHA1:
3
- metadata.gz: e049e1cd01093d886d6fdff3d0a20aec5f585574
4
- data.tar.gz: 7c29632aca25f3ca567681a5ff847eb170a0bf2e
2
+ SHA256:
3
+ metadata.gz: 3d4873e82c2906833aa5480dcd264453e839b62a67254e8bd6c43c361430be8b
4
+ data.tar.gz: 4958041c344dcb46dae8142b07872995d3e649bd9e5bc94befc7f476a5bd45b3
5
5
  SHA512:
6
- metadata.gz: 63ca7f9ed808b3b17a4f9f5c6f69c1b5f27b02773af4b32fed7cb387632e2e4077f1d2519afb39bb883f5eb6f870f5e1ef80aa629ad4be528884c66db4b8d705
7
- data.tar.gz: 532ede4bdd2deb210c246e7ffdc3ed9456b88a65d53df4a4667689096fa52b452e145d8c91a84c0adad104a84ced0768c034af7018f4030e336579d4e9badc0f
6
+ metadata.gz: c29745b0d6d5e43c81907857eb695017cce649d30b9905e0baffe52cf8385fa4073bdaad5021c936f57b87196cf9288659351ef4f9e63268b2f35c0d364f8e86
7
+ data.tar.gz: d1a4eff4362d6e9a4fbe5a644cbf385c8aaf66d56baf2eb0a1e3cc3d1330f1ec791125906cb2f62dcecf616394861b066cf0838e76f3e95ac66d9318cd6724c9
data/GPLv2 CHANGED
@@ -1,8 +1,8 @@
1
- GNU GENERAL PUBLIC LICENSE
2
- Version 2, June 1991
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
3
 
4
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
6
  Everyone is permitted to copy and distribute verbatim copies
7
7
  of this license document, but changing it is not allowed.
8
8
 
@@ -73,7 +73,7 @@ module Prawn
73
73
  def load_file(package, file)
74
74
  start_new_page
75
75
  example = ExampleFile.new(package, "#{file}.rb")
76
- eval example.generate_block_source
76
+ eval example.generate_block_source, nil, File.join(Prawn::ManualBuilder.manual_dir, example.parent_folder_name, example.filename), example.generated_block_line
77
77
  end
78
78
 
79
79
 
@@ -129,7 +129,7 @@ module Prawn
129
129
  code(example.source)
130
130
 
131
131
  if example.eval?
132
- eval_code(example.source)
132
+ eval_code(example)
133
133
  else
134
134
  source_link(example)
135
135
  end
@@ -212,7 +212,8 @@ module Prawn
212
212
 
213
213
  # Renders a dashed line and evaluates the code inline
214
214
  #
215
- def eval_code(source)
215
+ def eval_code(example)
216
+ source = example.source
216
217
  move_down(RHYTHM)
217
218
 
218
219
  dash(3)
@@ -223,18 +224,12 @@ module Prawn
223
224
 
224
225
  move_down(RHYTHM*3)
225
226
  begin
226
- eval(source)
227
+ eval source, nil, File.join(Prawn::ManualBuilder.manual_dir, example.parent_folder_name, example.filename), example.generated_block_line
227
228
  rescue => e
228
229
  puts "Error evaluating example: #{e.message}"
229
230
  puts
230
231
  puts "---- Source: ----"
231
- puts
232
- source.lines.each_with_index do |l, i|
233
- puts format('% 4d: %s', i + 1, l)
234
- end
235
- puts
236
- puts "---- Backtrace: ----"
237
- puts e.backtrace
232
+ puts source
238
233
  end
239
234
  end
240
235
 
@@ -44,7 +44,15 @@ module Prawn
44
44
 
45
45
  block.gsub(/^( ){2}/, "")
46
46
  end
47
-
47
+
48
+ def generated_block_line
49
+ pre_block = @data.slice(/.*\w+\.generate.*? do\n/m)
50
+
51
+ return 1 unless pre_block
52
+
53
+ pre_block.lines.length + 1
54
+ end
55
+
48
56
  # Return either the full_source or the generate_block_source according
49
57
  # to the options
50
58
  #
@@ -65,14 +73,19 @@ module Prawn
65
73
  # Then removes the '#' signs, reflows the line breaks and return the result
66
74
  #
67
75
  def introduction_text
68
- intro_lines
69
- .map do |line|
70
- line
71
- .gsub(/\A\s*# (?=\S)/m, ' ')
72
- .gsub(/\A\s*#/, '')
73
- .strip
74
- end
75
- .join("\n")
76
+ intro = @data.lines.grep(/^#/)
77
+
78
+ intro.shift if intro.first =~ /^#!/
79
+ intro.shift if intro.first =~ /coding:/
80
+ intro.shift if intro.first =~ /frozen_string_literal:/
81
+
82
+ intro = intro.join
83
+
84
+ intro.gsub!(/\n# (?=\S)/m, ' ')
85
+ intro.gsub!(/^#/, '')
86
+ intro.gsub!("\n", "\n\n")
87
+ intro.rstrip!
88
+ intro
76
89
  end
77
90
 
78
91
  # Returns a human friendly version of the example file name
@@ -109,18 +122,7 @@ module Prawn
109
122
 
110
123
  data.encode(::Encoding::UTF_8)
111
124
  end
112
-
113
- def intro_lines
114
- @data
115
- .lines
116
- .grep(/^#/)
117
- .reject do |line|
118
- line.start_with?('#!') ||
119
- /coding:/.match(line) ||
120
- /\A\s*#\s*frozen_string_literal:/.match(line) ||
121
- /\A\s*#\s*rubocop:/.match(line)
122
- end
123
- end
125
+
124
126
  end
125
127
  end
126
128
  end
@@ -1,20 +1,20 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Prawn
4
- module ManualBuilder
5
- # The Prawn::ManualBuilder::ExamplePackage class is a utility class to
6
- # handle the packaging of individual examples within a hierarchy
4
+ module ManualBuilder
5
+ # The Prawn::ManualBuilder::ExamplePackage class is a utility class to
6
+ # handle the packaging of individual examples within a hierarchy
7
7
  # when building the manual.
8
8
  class ExamplePackage
9
9
  attr_reader :intro_block, :folder_name
10
10
 
11
11
  attr_writer :name
12
-
12
+
13
13
  def initialize(folder_name)
14
14
  @folder_name = folder_name
15
15
  @hierarchy = []
16
16
  end
17
-
17
+
18
18
  # Stores a new ExampleSection in the hierarchy and yields it to a block
19
19
  #
20
20
  def section(name)
@@ -22,31 +22,31 @@ module Prawn
22
22
  yield s
23
23
  @hierarchy << s
24
24
  end
25
-
25
+
26
26
  # Stores a new ExampleFile in the hierarchy
27
27
  #
28
28
  def example(filename, options={})
29
29
  @hierarchy << ExampleFile.new(self, "#{filename}.rb", options)
30
30
  end
31
-
31
+
32
32
  # Stores a block with code to be evaluated when rendering the package cover
33
33
  #
34
34
  def intro(&block)
35
35
  @intro_block = block
36
36
  end
37
-
37
+
38
38
  # Returns a human friendly version of the package name
39
39
  #
40
40
  def name
41
41
  @name ||= @folder_name.gsub("_", " ").capitalize
42
42
  end
43
-
43
+
44
44
  # Renders a cover page for the package to a pdf and iterates the examples
45
45
  # hierarchy delegating the examples and sections to be rendered as well
46
46
  #
47
47
  def render(pdf)
48
48
  pdf.render_package_cover(self)
49
-
49
+
50
50
  @hierarchy.each do |node|
51
51
  node.render(pdf)
52
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn-manual_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Doria
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-04-27 00:00:00.000000000 Z
12
+ date: 2019-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: coderay
@@ -46,9 +46,7 @@ files:
46
46
  - lib/prawn/manual_builder/example_file.rb
47
47
  - lib/prawn/manual_builder/example_package.rb
48
48
  - lib/prawn/manual_builder/example_section.rb
49
- - lib/prawn/manual_builder/manual.rb
50
49
  - lib/prawn/manual_builder/syntax_highlight.rb
51
- - lib/prawn/manual_builder/version.rb
52
50
  homepage:
53
51
  licenses:
54
52
  - PRAWN
@@ -63,15 +61,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
61
  requirements:
64
62
  - - ">="
65
63
  - !ruby/object:Gem::Version
66
- version: '2.3'
64
+ version: 1.9.3
67
65
  required_rubygems_version: !ruby/object:Gem::Requirement
68
66
  requirements:
69
67
  - - ">="
70
68
  - !ruby/object:Gem::Version
71
69
  version: '0'
72
70
  requirements: []
73
- rubyforge_project:
74
- rubygems_version: 2.6.14
71
+ rubygems_version: 3.0.3
75
72
  signing_key:
76
73
  specification_version: 4
77
74
  summary: A tool for writing manuals for Prawn and Prawn accessories
@@ -1,14 +0,0 @@
1
- module Prawn
2
- module ManualBuilder
3
- class Manual
4
- # Creates a new ExamplePackage object and yields it to a block in order
5
- # for it to be populated with examples, sections and some introduction
6
- # text. Used on the package files.
7
- def package(package, &block)
8
- ep = ExamplePackage.new(package)
9
- ep.instance_eval(&block)
10
- ep.render(self)
11
- end
12
- end
13
- end
14
- end
@@ -1,5 +0,0 @@
1
- module Prawn
2
- module ManualBuilder
3
- VERSION = '0.3.0'
4
- end
5
- end