14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/slideshow/helpers/syntax/uv_helper.rb', line 14
def uv_worker( code, opts )
lang = opts.fetch( :lang, UV_LANG )
line_numbers_value = opts.fetch( :line_numbers, .get( 'code-line-numbers', UV_LINE_NUMBERS ))
line_numbers = (line_numbers_value =~ /true|yes|on/i) ? true : false
theme = opts.fetch( :theme, .get( 'code-theme', UV_THEME )).tr( '-', '_' )
code_highlighted = Uv.parse( code, "xhtml", lang, line_numbers, theme )
uv_first_time = session.fetch( :uv_first_time, true )
if uv_first_time
session[ :uv_first_time ] = false
logger.debug "cache_dir=#{config.cache_dir}"
FileUtils.mkdir(config.cache_dir) unless File.exists?(config.cache_dir) if config.cache_dir
Uv.copy_files "xhtml", config.cache_dir
end
uv_themes = session[ :uv_themes ] ||= {}
if uv_themes[ theme ].nil?
uv_themes[ theme ] = true
theme_content = File.read_utf8( "#{config.cache_dir}/css/#{theme}.css" )
theme_out = %{/* styles for ultraviolet code syntax highlighting theme '#{theme}' */\n\n}
theme_out << theme_content
theme_out << %{\n\n}
content_for( :css, theme_out )
end
css_class = 'code'
css_class_opt = opts.fetch( :class, nil ) css_class << " #{css_class_opt}" if css_class_opt
name = opts.fetch( :name, nil )
txmt_value = opts.fetch( :txmt, .code_txmt )
txmt = (txmt_value =~ /true|yes|on/i) ? true : false
out = %{<pre class='#{css_class}'>\n}
out << code_highlighted
out << %{</pre>\n}
if name
out << %{<div class="codeurl">}
out << %{<a href="txmt://open?url=file://#{File.expand_path(name)}">} if txmt
out << name
out << %{</a>} if txmt
out << %{</div>\n}
end
return out
end
|