#{escape(o)}}
99 | end
100 |
101 | # Escape HTML.
102 | #
103 | # {{ content.html | escape }}
104 | def self.escape(o)
105 | return invalid_encoding(o.name) unless o.valid_data?
106 | CGI::escapeHTML(o.data)
107 | end
108 |
109 | # Embed syntax-highlighted source code.
110 | #
111 | # {{ source.rb }}
112 | # {{ content.html | code }}
113 | # {{ chat.irc | code(nolines: true) }}
114 | # {{ rubyfile.txt | code(type: :ruby) }}
115 | def self.code(o)
116 | return invalid_encoding(o.name) unless o.valid_data?
117 |
118 | # `nolines` option will override default (lines).
119 | nolines = o.args.to_hash.delete(:nolines)
120 |
121 | # `type` option will override default type.
122 | ext = o.args.to_hash.delete(:type) || File.extname(o.name)[1..-1]
123 |
124 | # Merge args.
125 | # TODO: figure out options: hl_lines: [1,3,5], linenostart
126 | args = {}
127 | args.merge!(linenos: :table, anchorlinenos: true, lineanchors: o.name) unless nolines
128 | args.merge!(o.args)
129 |
130 | # Construct pygmentize CLI params and highlight code.
131 | params = args.map {|k, v| ['-P', %Q{#{k}="#{v}"}]}.flatten
132 | code = Pygmentize.process(o.data, ext, params)
133 |
134 | unindent(<<-EOF)
135 |
145 | def self.url(o)
146 | if o.page.shown_fs_mods?
147 | "#{o.page.url}/#{o.name}"
148 | else
149 | "#{o.page.commit.url}/#{o.name}"
150 | end
151 | end
152 |
153 | # Embed an asset script.
154 | #
155 | # {{ awesome.js | script }}
156 | # {{ awesome.js | script(id: "test") }}
157 | def self.script(o)
158 | %Q{}
159 | end
160 |
161 | # Embed an asset CSS stylesheet.
162 | #
163 | # {{ pretty.css | css }}
164 | # {{ pretty.css | css(media: "screen") }}
165 | def self.css(o)
166 | %Q{}
167 | end
168 |
169 | # Embed an asset image.
170 | #
171 | # {{ image.jpg | image }}
172 | # {{ image.jpg | image(width: "20", style: "float:right") }}
173 | def self.image(o)
174 | o.default_attr = 'alt'
175 | %Q{