code_slide 1.0.0 → 1.0.1

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
- SHA1:
3
- metadata.gz: aebc8a3009b9b263056b648e126f867b1b8dca98
4
- data.tar.gz: 8f306a98bf274c541c4c65a4d6c5c6c9a9e3c118
2
+ SHA256:
3
+ metadata.gz: e099d9e095ef6fa4d522b8257e44830208e5d7a3301c7de528d2e096d3694cde
4
+ data.tar.gz: 4e301e8e48f951ae28052684dd1536d77251b4ccc3a1007ea75dbe1d0b8567e6
5
5
  SHA512:
6
- metadata.gz: f1ea745fc473cabdf4a48679e6da926a8f6074611e3d82ea1054f51eecc00d3a42d6aaff6e66a0b9596a7c3971a504b4c39b8c5ea1b41fcdabb75acac11321d9
7
- data.tar.gz: ea9222bc9825af6abf019abfee1496db11f507234d72a87e52995e79bcdc86dbec9df4f20cf43fe12ea1db2493e02ca530e6bbe4415f379ff69333621e7ecd5b
6
+ metadata.gz: f2fb5727fc5b39321cdcef5d73361a32624fb1f6c7f95c9bcc7fafc8366980c7e15d46c8155f3518a59979da02f27f91b8960bbeb24d83a8f55498c12665bb35
7
+ data.tar.gz: b32f8c6a86d58987673aeaa2633cd9b55386fada8510a36c4b28c251a6b5fed4a7cfe7549ace727b9920e8098737fdc4a1ed570cd29514c344c155295db455a9
@@ -4,19 +4,42 @@ require 'code_slide/png_formatter'
4
4
 
5
5
  module CodeSlide
6
6
  class Snippet
7
+ MARK_PREFIX = %r{^\s*(#|//)\s*}
8
+ START_MARK = /#{MARK_PREFIX}START:\s*/
9
+ END_MARK = /#{MARK_PREFIX}END:\s*/
10
+
7
11
  def self.from_file(filename, options = {})
8
12
  options = options.dup
9
13
 
10
- start = options.delete(:start) || 1
11
- finish = options.delete(:finish) || -1
14
+ lines = File.readlines(filename)
15
+ mark = options.delete(:mark)
16
+
17
+ if mark
18
+ start = lines.index { |line| line =~ /#{START_MARK}#{mark}\s*$/i }
19
+ finish = lines.index { |line| line =~ /#{END_MARK}#{mark}\s*$/i }
20
+
21
+ # if start is defined, don't include the comment itself
22
+ start += 2 if start
23
+ else
24
+ start = options.delete(:start)
25
+ finish = options.delete(:finish)
26
+ end
12
27
 
28
+ start ||= 1
29
+ finish ||= -1
13
30
  line_start = options[:line_number_start] || start
14
31
 
15
32
  # assume people number their file lines starting at 1
16
33
  start -= 1 if start > 0
17
34
  finish -= 1 if finish > 0
18
35
 
19
- text = File.read(filename).lines[start..finish].join
36
+ text = lines[start..finish].join
37
+
38
+ if options.delete(:strip_indent)
39
+ indent = text[/^\s*/]
40
+ text.gsub!(/^#{indent}/m, "")
41
+ end
42
+
20
43
  new(text,
21
44
  options.merge(lang: options[:lang] || detect_language_type(filename),
22
45
  line_number_start: line_start))
@@ -52,7 +75,7 @@ module CodeSlide
52
75
  use_font(@font, bold: @bold,
53
76
  italic: @italic,
54
77
  bold_italic: @bold_italic).
55
- build_pdf(options).
78
+ build_pdf(**options).
56
79
  render_file(filename)
57
80
  end
58
81
 
@@ -33,6 +33,12 @@ integer:
33
33
  color: 'd09a6a'
34
34
  float:
35
35
  color: 'd09a6a'
36
+ regexp:
37
+ color: '5ab6c1'
38
+ char:
39
+ color: '5ab6c1'
40
+ modifier:
41
+ color: '5ab6c1'
36
42
  predefined-constant:
37
43
  color: 'd09a6a'
38
44
  inline-delimiter:
@@ -33,6 +33,12 @@ integer:
33
33
  color: '976715'
34
34
  float:
35
35
  color: '976715'
36
+ regexp:
37
+ color: '1485ba'
38
+ char:
39
+ color: '1485ba'
40
+ modifier:
41
+ color: '1485ba'
36
42
  predefined-constant:
37
43
  color: '976715'
38
44
  inline-delimiter:
@@ -1,3 +1,3 @@
1
1
  module CodeSlide
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.0.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_slide
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamis Buck
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-15 00:00:00.000000000 Z
11
+ date: 2024-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.1'
19
+ version: '2.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.1'
26
+ version: '2.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: coderay
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.6'
47
+ version: '1.16'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.6'
54
+ version: '1.16'
55
55
  description: |2
56
56
  A library for turning code snippets into slides. Automatically turn your
57
57
  source code into syntax-highlighted PDFs and PNGs. Take the tedium out
@@ -77,7 +77,7 @@ homepage: https://github.com/jamis/code_slide
77
77
  licenses:
78
78
  - MIT
79
79
  metadata: {}
80
- post_install_message:
80
+ post_install_message:
81
81
  rdoc_options: []
82
82
  require_paths:
83
83
  - lib
@@ -92,9 +92,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  requirements: []
95
- rubyforge_project:
96
- rubygems_version: 2.5.1
97
- signing_key:
95
+ rubygems_version: 3.4.19
96
+ signing_key:
98
97
  specification_version: 4
99
98
  summary: Generate PDF/PNG slides from source code
100
99
  test_files: []