This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'erb' | |
class Ansible | |
class TemplateParams | |
attr_accessor :content, :helper | |
# Public: Initializes the Template Params context. | |
# | |
# content - the Ansible content | |
def initialize(content) | |
@content = content | |
@helper = Helper.new | |
end | |
# Public: Gets the ERB binding. | |
# | |
# Returns a Binding instance. | |
def get_binding | |
binding | |
end | |
end | |
class Helper | |
# Public: Applies html format to a line. | |
# | |
# line - a String | |
# | |
# Returns a String. | |
def format_line(line) | |
# replaces whitespaces with the html version | |
line = line.gsub(" ", " ") | |
# replaces ok=123 | |
line = line.gsub(/(\w+)=(\d+)/, "<span class=\"\\1\">\\1=\\2</span>") | |
# replaces ok:... | |
if status = line.split(":").first | |
line = "<span class=\"#{status}\">#{line}</span>" | |
end | |
line | |
end | |
end | |
# Public: Applies the syntax highlight. | |
# | |
# content - a String | |
# | |
# Returns a String. | |
def parse(content) | |
source = ERB.new(File.read(File.dirname(__FILE__) + "/ansible.html.erb", nil)) | |
source.result(TemplateParams.new(content).get_binding) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment