class TurnipFormatter::Template

Public Class Methods

add_javascript(script) click to toggle source
# File lib/turnip_formatter/template.rb, line 18
def add_javascript(script)
  case
  when local_file?(script)
    js_code_list << File.read(script)
  when remote_url?(script)
    js_file_list << script
  end
end
add_stylesheet(stylesheet) click to toggle source
# File lib/turnip_formatter/template.rb, line 27
def add_stylesheet(stylesheet)
  case
  when local_file?(stylesheet)
    css_code_list << File.read(stylesheet)
  when remote_url?(stylesheet)
    css_file_list << stylesheet
  end
end
project_name() click to toggle source
# File lib/turnip_formatter/template.rb, line 7
def project_name
  TurnipFormatter.configuration.title
end
render_javascript_codes() click to toggle source
# File lib/turnip_formatter/template.rb, line 36
def render_javascript_codes
  js_code_list.join("\n")
end
render_stylesheet_codes() click to toggle source
# File lib/turnip_formatter/template.rb, line 46
def render_stylesheet_codes
  codes = TurnipFormatter.step_templates.map do |template|
    template.class.css
  end

  codes.concat(css_code_list).join("\n")
end
reset!() click to toggle source
# File lib/turnip_formatter/template.rb, line 11
def reset!
  @js_code_list = []
  @js_file_list = []
  @css_code_list = []
  @css_file_list = []
end

Private Class Methods

css_code_list() click to toggle source
# File lib/turnip_formatter/template.rb, line 70
def css_code_list
  @css_code_list ||= []
end
css_file_list() click to toggle source
# File lib/turnip_formatter/template.rb, line 74
def css_file_list
  @css_file_list ||= []
end
js_code_list() click to toggle source
# File lib/turnip_formatter/template.rb, line 62
def js_code_list
  @js_code_list ||= []
end
js_file_list() click to toggle source
# File lib/turnip_formatter/template.rb, line 66
def js_file_list
  @js_file_list ||= []
end
local_file?(path) click to toggle source
# File lib/turnip_formatter/template.rb, line 78
def local_file?(path)
  File.exist? path
end
remote_url?(path) click to toggle source
# File lib/turnip_formatter/template.rb, line 82
def remote_url?(path)
  uri = URI.parse(path)
  return true if %w(http https).include?(uri.scheme)
  return true if uri.scheme.nil? && path.start_with?('//')
  false
rescue URI::InvalidURIError
  false
end