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

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(options = {})
  force_remote = options.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(options = {})
  force_remote = options.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(options = {})
  force_remote = options.delete(:remote)

  options[:numbers] = options.delete(:line_numbers) if options.include?(:line_numbers)
  options[:syntax] = options.delete(:language) if options.include?(:language)
  
  options = { :numbers => false, :syntax => 'ruby', :theme => 'mac_classic' }.merge(options)
  
  if LOCAL_UV && ! force_remote
    Uv.parse(self, 'xhtml', options[:syntax], options[:numbers], options[:theme])
  else
    RestClient.post "http://#{KULRII_HOST}/parse", options.merge(:text => self)
  end
end