Module: Kulriir
- Defined in:
- lib/kulriir.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- LOCAL_UV =
begin require 'uv' true rescue LoadError => e false end
- KULRII_HOST =
'kulrii.heroku.com'
Class Method Summary collapse
Instance Method Summary collapse
-
#highlight(options = {}) ⇒ Object
return a syntax-highlighted version of the string.
Class Method Details
.included(base) ⇒ Object
14 15 16 |
# File 'lib/kulriir.rb', line 14 def self.included(base) base.extend ClassMethods end |
.syntaxes(options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/kulriir.rb', line 48 def syntaxes( = {}) force_remote = .delete(:remote) if LOCAL_UV && ! force_remote Uv.syntaxes else REXML::Document.new(RestClient.get("http://#{KULRII_HOST}/syntaxes")).elements.collect('syntaxes/syntax') { |e| e.text } end end |
.themes(options = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/kulriir.rb', line 58 def themes( = {}) force_remote = .delete(:remote) if LOCAL_UV && ! force_remote Uv.themes else REXML::Document.new(RestClient.get("http://#{KULRII_HOST}/themes")).elements.collect('themes/theme') { |e| e.text } end end |
Instance Method Details
#highlight(options = {}) ⇒ Object
return a syntax-highlighted version of the string
options:
numbers: boolean indicating whether or not to include line numbers line_numbers: legacy equivalent for 'numbers' option syntax: language to use for highlighting language: legacy equivalent for 'syntax' option theme: theme for highlighting
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kulriir.rb', line 32 def highlight( = {}) force_remote = .delete(:remote) [:numbers] = .delete(:line_numbers) if .include?(:line_numbers) [:syntax] = .delete(:language) if .include?(:language) = { :numbers => false, :syntax => 'ruby', :theme => 'mac_classic' }.merge() if LOCAL_UV && ! force_remote Uv.parse(self, 'xhtml', [:syntax], [:numbers], [:theme]) else RestClient.post "http://#{KULRII_HOST}/parse", .merge(:text => self) end end |