Sha256: 1079c9835942124847cbf1c2b1e89d574304f76530d6824bb90c6d1449c4acd5

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

# -*- coding: utf-8 -*-

require 'turnip_formatter/template'
require 'sass'

module TurnipFormatter
  class Template
    class << self
      def project_name
        RSpec.configuration.respond_to?(:project_name) ? RSpec.configuration.project_name : 'Turnip'
      end

      def add_js(js_string)
        js_list << js_string
      end

      def add_js_file(file)
        if URI(file).scheme
          js_file_list << file
        else
          js_list << File.read(file)
        end
      end

      def add_scss(scss_string)
        css_list << Sass::Engine.new(scss_string, scss_option).render
      end

      def add_css_file(file)
        if URI(file).scheme
          css_file_list << file
        else
          add_scss_file(file)
        end
      end

      def add_scss_file(path)
        css_list << Sass::Engine.for_file(path, scss_option).render
      end

      def js_render
        js_list.join("\n")
      end

      def js_file_render
        js_file_list.map do |file|
          "<script src=\"#{file}\" type=\"text/javascript\"></script>"
        end.join("\n")
      end

      def css_render
        css_list.join("\n")
      end

      def css_file_render
        css_file_list.map do |file|
          "<link rel=\"stylesheet\" href=\"#{file}\">"
        end.join("\n")
      end

      def js_list
        @js_list ||= []
      end

      def js_file_list
        @js_file_list ||= []
      end

      def css_list
        @css_list ||= []
      end

      def css_file_list
        @css_file_list ||= []
      end

      def scss_option
        { syntax: :scss, style: :compressed }
      end
    end
  end
end

(File.dirname(__FILE__) + '/template').tap do |dirname|
  TurnipFormatter::Template.add_css_file(dirname + '/turnip_formatter.scss')
  TurnipFormatter::Template.add_js_file(dirname + '/turnip_formatter.js')
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
turnip_formatter-0.2.11 lib/turnip_formatter/template.rb
turnip_formatter-0.2.10 lib/turnip_formatter/template.rb
turnip_formatter-0.2.9 lib/turnip_formatter/template.rb