Module: Ink::Helper
- Included in:
- Formatter
- Defined in:
- lib/ink/helper.rb
Overview
The Ink::Helper module is great for shortcuts. On Rails applications, can be added to ApplicationHelper.
module ApplicationHelper
include InkHelper
end
Instance Method Summary collapse
-
#format(code, file) ⇒ Object
Return a code snippet formatted by using the Ink::Formatter.format method.
-
#highlight(code, options = {}) ⇒ Object
Return a code snippet highlighted in the specified language.
Instance Method Details
#format(code, file) ⇒ Object
Return a code snippet formatted by using the Ink::Formatter.format method.
<%= format @code, "Rakefile" %>
15 16 17 |
# File 'lib/ink/helper.rb', line 15 def format(code, file) Ink::Formatter.format(code, file) end |
#highlight(code, options = {}) ⇒ Object
Return a code snippet highlighted in the specified language. When a :file option is provided, then language will be guessed by the filename. If no language is specified will set to :text.
<%= highlight @code, :file => "Rakefile" %>
<%= highlight @code, :language => :ruby %>
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ink/helper.rb', line 27 def highlight(code, = {}) file = Tempfile.new("highlight") File.open(file.path, "w+") do |f| f << "#{code}\n" end if [:file] language = Highlight.guess_by_filename([:file]) else language = [:language] || :text end code = Ink::Highlight.highlight(file.path, :language => language) %[<div class="code #{language}">#{code}</div>] end |