sbfaulkner-kulriir 1.0.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.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 unwwwired.net
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,60 @@
1
+ # kulriir
2
+
3
+ Syntax highlighting using the kulrii.heroku.com web service.
4
+
5
+ ## WHY?
6
+
7
+ I have historically used ultraviolet for any syntax highlighting. However, in
8
+ order to use ultraviolet, you need to be able to use the oniguruma library.
9
+ Unfortunately, some hosting services (like the Media Temple grid service) do
10
+ not support this library. I needed another solution, and it seemed like
11
+ something that could be outsourced... the only solution I found seemed to be
12
+ the pygment.com javascript-based solution. I cobbled together my pygmalion
13
+ gem, which does the job, but it seemed I could do something myself that
14
+ didn't rely on an undocumented api.
15
+
16
+ ## Installation
17
+
18
+ Run the following if you haven't already:
19
+
20
+ $ gem sources -a http://gems.github.com
21
+
22
+ Install the gem(s):
23
+
24
+ $ sudo gem install -r sbfaulkner-kulriir
25
+
26
+ ## Usage
27
+
28
+ In ruby...
29
+
30
+ require 'kulriir'
31
+ ...
32
+ string.highlight
33
+ string.highlight(:language => 'javascript')
34
+ string.highlight(:language => 'ruby', :line_numbers => true)
35
+
36
+ From the command-line...
37
+
38
+ Usage: kulriir [options] [file ...]
39
+
40
+ Options:
41
+ -h, --help Display this message.
42
+ -l, --language=name The language for the code to be highlighted.
43
+ -n, --line-numbers Include line numbers.
44
+
45
+ ## Example
46
+
47
+ File.read('hello.rb').highlight(:numbers => true)
48
+
49
+ Results in...
50
+
51
+ <pre class="mac_classic"><span class="line-numbers"> 1 </span> <span class="Keyword">def</span> <span class="FunctionName">hello</span>
52
+ <span class="line-numbers"> 2 </span> puts <span class="String"><span class="String">&quot;</span>hello<span class="String">&quot;</span></span>
53
+ <span class="line-numbers"> 3 </span> <span class="Keyword">end</span>
54
+ </pre>
55
+
56
+
57
+ ## Legal
58
+
59
+ **Author:** S. Brent Faulkner <brentf@unwwwired.net>
60
+ **License:** Copyright &copy; 2008 unwwwired.net, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ Gem::manage_gems
3
+ require 'rake/gempackagetask'
4
+
5
+ load File.join(File.dirname(__FILE__),'kulriir.gemspec')
6
+
7
+ Rake::GemPackageTask.new(SPEC) do |pkg|
8
+ end
9
+
10
+ task :default => :package
data/bin/kulriir ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'getoptlong'
5
+
6
+ require 'kulriir'
7
+
8
+ opts = GetoptLong.new(
9
+ [ "--help", "-h", GetoptLong::NO_ARGUMENT ],
10
+ [ "--numbers", "-n", GetoptLong::NO_ARGUMENT ],
11
+ [ "--syntaxes", "-S", GetoptLong::NO_ARGUMENT ],
12
+ [ "--syntax", "-s", GetoptLong::REQUIRED_ARGUMENT ],
13
+ [ "--themes", "-T", GetoptLong::NO_ARGUMENT ],
14
+ [ "--theme", "-t", GetoptLong::REQUIRED_ARGUMENT ]
15
+ )
16
+
17
+ OPTIONS = {
18
+ :syntax => 'plain_text',
19
+ :theme => 'mac_classic',
20
+ :numbers => 'off'
21
+ }
22
+
23
+ opts.each do |opt, arg|
24
+ case opt
25
+ when '--help'
26
+ puts "Usage: kulriir [options] [file ...]"
27
+ puts "\nOptions:"
28
+ puts " -h, --help Display this message."
29
+ puts " -n, --numbers Include line numbers."
30
+ puts " -S, --syntaxes List all supported syntaxes."
31
+ puts " -s, --syntax=name The language for the code to be highlighted."
32
+ puts " -T, --themes List all supported themes."
33
+ puts " -t, --theme=name The theme to use for code highlighting."
34
+ exit 1
35
+ when '--numbers'
36
+ OPTIONS[:numbers] = true
37
+ when '--syntaxes'
38
+ puts Kulriir.syntaxes.join("\n")
39
+ exit
40
+ when '--syntax'
41
+ OPTIONS[:syntax] = arg
42
+ when '--themes'
43
+ puts Kulriir.themes.join("\n")
44
+ exit
45
+ when '--theme'
46
+ OPTIONS[:theme] = arg
47
+ end
48
+ end
49
+
50
+ if ARGV.empty?
51
+ puts STDIN.read.highlight(OPTIONS)
52
+ else
53
+ ARGV.each_with_index do |file,id|
54
+ puts File.read(file).highlight(OPTIONS)
55
+ end
56
+ end
data/kulriir.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ SPEC = Gem::Specification.new do |s|
2
+ # identify the gem
3
+ s.name = "kulriir"
4
+ s.version = "1.0.0"
5
+ s.author = "S. Brent Faulkner"
6
+ s.email = "brentf@unwwwired.net"
7
+ s.homepage = "http://github.com/sbfaulkner/kulriir"
8
+ # platform of choice
9
+ s.platform = Gem::Platform::RUBY
10
+ # description of gem
11
+ s.summary = "Syntax highlighting using the kulrii.heroku.com web service"
12
+ s.files = %w(bin/kulriir lib/kulriir.rb MIT-LICENSE Rakefile README.markdown kulriir.gemspec)
13
+ s.require_path = "lib"
14
+ # s.test_file = "test/kulriir.rb"
15
+ s.has_rdoc = true
16
+ s.extra_rdoc_files = ["README.markdown"]
17
+ s.add_dependency "rest-client"
18
+ s.executables = ["kulriir"]
19
+ s.rubyforge_project = 'kulriir'
20
+ end
data/lib/kulriir.rb ADDED
@@ -0,0 +1,45 @@
1
+ require 'rest_client'
2
+ require 'rexml/document'
3
+
4
+ module Kulriir
5
+ KULRII_HOST = 'kulrii.heroku.com'
6
+
7
+ def self.included(base)
8
+ base.extend ClassMethods
9
+ end
10
+
11
+ module ClassMethods
12
+ end
13
+
14
+ #
15
+ # return a syntax-highlighted version of the string
16
+ #
17
+ # options:
18
+ #
19
+ # **numbers**: boolean indicating whether or not to include line numbers
20
+ # **line_numbers**: legacy equivalent for 'numbers' option
21
+ # **syntax**: language to use for highlighting
22
+ # **language**: legacy equivalent for 'syntax' option
23
+ # **theme**: theme for highlighting
24
+ #
25
+ def highlight(options = {})
26
+ options[:numbers] = options.delete(:line_numbers) if options.include?(:line_numbers)
27
+ options[:syntax] = options.delete(:language) if options.include?(:language)
28
+
29
+ options[:syntax] ||= 'ruby'
30
+
31
+ RestClient.post "http://#{KULRII_HOST}/parse", options.merge(:text => self)
32
+ end
33
+
34
+ class << self
35
+ def syntaxes
36
+ REXML::Document.new(RestClient.get("http://#{KULRII_HOST}/syntaxes")).elements.collect('syntaxes/syntax') { |e| e.text }
37
+ end
38
+
39
+ def themes
40
+ REXML::Document.new(RestClient.get("http://#{KULRII_HOST}/themes")).elements.collect('themes/theme') { |e| e.text }
41
+ end
42
+ end
43
+ end
44
+
45
+ String.send :include, Kulriir
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sbfaulkner-kulriir
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - S. Brent Faulkner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-27 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rest-client
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description:
25
+ email: brentf@unwwwired.net
26
+ executables:
27
+ - kulriir
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README.markdown
32
+ files:
33
+ - bin/kulriir
34
+ - lib/kulriir.rb
35
+ - MIT-LICENSE
36
+ - Rakefile
37
+ - README.markdown
38
+ - kulriir.gemspec
39
+ has_rdoc: true
40
+ homepage: http://github.com/sbfaulkner/kulriir
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project: kulriir
61
+ rubygems_version: 1.2.0
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: Syntax highlighting using the kulrii.heroku.com web service
65
+ test_files: []
66
+