Sha256: 9ae8efb90faf69c7c1b5049ee5b469dd7433c75510cd2009947738e7e2a44821

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

require "coffee-processing/version"
require 'erubis'
require 'coffee-script'

module CoffeeProcessing
  def self.compile javascript_object, code
    first_line = code.lines.map(&:chomp).find { |line| !line.empty? }

    if first_line && indentation = first_line.scan(/^\s+/).first
      code = code.lines.map { |line| line.sub(/^#{indentation}/, '')}.join
    end

    code = code.lines.map { |line| "#{line}  " }.join
    code = code.strip

    CoffeeScript.compile(
      Erubis::Eruby.new(
        File.read File.join(
          File.dirname(__FILE__),
          'coffee-processing',
          'boilerplate.coffee.erb'
        )
      ).result(binding)
    )
  end

  def self.generate_template_page javascript_object, code, output_dir
    require 'fileutils'
    FileUtils.mkdir_p output_dir
    File.open(File.join(output_dir, 'sketch.js'), 'w') do |f|
      f << compile(javascript_object, code)
    end
    File.open(File.join(output_dir, 'index.html'), 'w') do |f|
      f <<
        Erubis::Eruby.new(
          File.read File.join(
            File.dirname(__FILE__),
            'coffee-processing',
            'template.html.erb'
          )
        ).result(binding)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
coffee-processing-0.0.3 lib/coffee-processing.rb
coffee-processing-0.0.2 lib/coffee-processing.rb
coffee-processing-0.0.1 lib/coffee-processing.rb