octopress-code-highlighter 4.0.0 → 4.0.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
2
  SHA1:
3
- metadata.gz: d735422e3324ead88b068fe845d4709639937a8d
4
- data.tar.gz: b2a2478389f20fdf6dcb7a124f6654617588940e
3
+ metadata.gz: 33493bd9308df9d2b527e317df57f46a9216722c
4
+ data.tar.gz: 79bd0fecc2631516853fedec37fada2cad7ad7a6
5
5
  SHA512:
6
- metadata.gz: b8580566712e1acd5d3500ca9def1b1042c402947048509d2ed5c28388006246ffd88ba5ce5b04a400035295fb4e4f0025805157d54d3cf73e6eacad6ea6f150
7
- data.tar.gz: 2252aaa56e019095cfb53f255521c18041cf51d280f05bcfbc49fa19ce8f2602589900bd7509d51ae000425ab57c941f426c64bf8e25a5248a15f840035b238b
6
+ metadata.gz: c611d12ea6b6cfe97d7aa4b2ea6c4c63f6ecfd17f63c71ed6e215518c8415238b1ad468714eec06240e33e4bed5f62929dda7346a6d76b30f5baceb661e02434
7
+ data.tar.gz: 6f24e5ca6ceed1dab0ad15527628bdbcfc8dd4f2f85e098c940b5606c61cbf18fb50bc3f0c8b1253a85c20d1940bf6a6586339a6dac3be4e6d22131fa2837c18
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.0.1
4
+ - Changed `get_range` method to `select_lines` which returns a code partial when `start`, `end` or `range` options are defined.
5
+
3
6
  ## 4.0.0
4
7
  - Removed stylesheets. Now use gem octopress-solarized for stylesheets.
5
8
  - Removed dependency on Octopress Ink.
@@ -39,6 +39,21 @@ module Octopress
39
39
  OptionsParser.new(input).clean_markup
40
40
  end
41
41
 
42
+ # Return a code partial when start, end, or range options are defined
43
+ #
44
+ def self.select_lines(code, options)
45
+ length = code.lines.count
46
+ start = options[:start] || 1
47
+ endline = options[:end] || length
48
+
49
+ if start > 1 or endline < length
50
+ raise "Code is #{length} lines long, cannot begin at line #{start}." if start > length
51
+ raise "Code lines starting line #{start} cannot be after ending line #{endline}." if start > endline
52
+ code = code.lines[(start - 1), (endline + 1)].join
53
+ end
54
+ code
55
+ end
56
+
42
57
  def self.highlight_failed(error, syntax, markup, code, file = nil)
43
58
  code_snippet = code.split("\n")[0..9].map{|l| " #{l}" }.join("\n")
44
59
  fail_message = "\nError while parsing the following markup#{" in #{file}" if file}:\n\n".red
@@ -19,17 +19,23 @@ module Octopress
19
19
  end
20
20
 
21
21
  def select_renderer
22
- begin
23
- require 'rouge'
24
- return 'rouge' if defined?(Rouge)
25
- rescue LoadError; end
26
- begin
27
- require 'pygments.rb'
28
- return 'pygments' if defined?(Pygments)
29
- rescue LoadError
30
- puts "To highlight code, install the gem pygments.rb or rouge.".red
31
- return 'plain'
22
+ case true
23
+ when renderer_available?('rouge')
24
+ require 'rouge'
25
+ return 'rouge'
26
+ when renderer_available?('pygments.rb')
27
+ require 'pygments'
28
+ return 'pygments'
29
+ else
30
+ $stderr.puts 'No syntax highlighting:'.yellow
31
+ $stderr.puts "\tInstall pygments.rb, rouge".yellow
32
32
  end
33
+
34
+ 'plain'
35
+ end
36
+
37
+ def renderer_available?(which)
38
+ Gem::Specification::find_all_by_name(which).any?
33
39
  end
34
40
 
35
41
  def highlight
@@ -133,12 +139,12 @@ module Octopress
133
139
  #
134
140
  def get_range(code, start, endline)
135
141
  length = code.lines.count
136
- start
142
+ start ||= 1
137
143
  endline ||= length
138
144
  if start > 1 or endline < length
139
145
  raise "#{filepath} is #{length} lines long, cannot begin at line #{start}" if start > length
140
146
  raise "#{filepath} is #{length} lines long, cannot read beyond line #{endline}" if endline > length
141
- code = code.split(/\n/).slice(start - 1, endline + 1 - start).join("\n")
147
+ code = code.split(/\n/).slice(start - 1, endline + 1).join("\n")
142
148
  end
143
149
  code
144
150
  end
@@ -1,6 +1,6 @@
1
1
  module Octopress
2
2
  module CodeHighlighter
3
- VERSION = "4.0.0"
3
+ VERSION = "4.0.1"
4
4
  end
5
5
  end
6
6
 
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopress-code-highlighter
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-13 00:00:00.000000000 Z
11
+ date: 2014-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorator
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.1.0
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
26
  version: 0.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry-debugger
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rouge
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.3.2
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.3.2
83
83
  description: Octopress's core plugin for rendering nice code blocks
@@ -87,9 +87,9 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .gitignore
91
- - .rspec
92
- - .travis.yml
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
93
  - CHANGELOG.md
94
94
  - Gemfile
95
95
  - LICENSE.txt
@@ -113,17 +113,17 @@ require_paths:
113
113
  - lib
114
114
  required_ruby_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - '>='
116
+ - - ">="
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - '>='
121
+ - - ">="
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.1.11
126
+ rubygems_version: 2.2.2
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: Octopress's core plugin for rendering nice code blocks