Sha256: cbdea7ca35f708d05b34e09135d7773edca55877a31be5e40b61a1a704a1e873

Contents?: true

Size: 778 Bytes

Versions: 30

Compression:

Stored size: 778 Bytes

Contents

# -*- coding: utf-8 -*-
require 'coffee-script'
require 'fileutils'

module TDiary
	module Rack
		module Assets
			class Precompile
				def initialize(app, environment = nil)
					@app = app
					@environment = environment
				end

				def call( env )
					@environment.each_file do |script|
						next unless script.to_s =~ /\.coffee\z/
						js_path = Pathname.new(script.to_s.gsub(/\.coffee\z/, '.js'))

						if !FileTest.exist?(js_path) || FileUtils.uptodate?(script, [js_path])
							File.open(js_path, 'w') do |js|
								js.write CoffeeScript.compile(File.read(script))
							end
						end
					end if @environment
					@app.call( env )
				end
			end
		end
	end
end

# Local Variables:
# mode: ruby
# indent-tabs-mode: t
# tab-width: 3
# ruby-indent-level: 3
# End:

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/tdiary-4.2.0/lib/tdiary/rack/assets/precompile.rb
tdiary-coffeescript-0.1.0 lib/tdiary/rack/assets/precompile.rb
tdiary-4.2.0 lib/tdiary/rack/assets/precompile.rb
tdiary-4.1.3 lib/tdiary/rack/assets/precompile.rb
tdiary-4.1.2 lib/tdiary/rack/assets/precompile.rb
tdiary-4.1.1 lib/tdiary/rack/assets/precompile.rb
tdiary-4.1.0 lib/tdiary/rack/assets/precompile.rb
tdiary-4.1.0.20141126 lib/tdiary/rack/assets/precompile.rb
tdiary-4.0.5.1 tdiary/rack/assets/precompile.rb
tdiary-4.0.5 tdiary/rack/assets/precompile.rb
tdiary-4.0.4 tdiary/rack/assets/precompile.rb
tdiary-4.0.3 tdiary/rack/assets/precompile.rb
tdiary-4.0.2.20140201 tdiary/rack/assets/precompile.rb
tdiary-4.0.2 tdiary/rack/assets/precompile.rb
tdiary-4.0.1.20131102 tdiary/rack/assets/precompile.rb
tdiary-4.0.1.20130929 tdiary/rack/assets/precompile.rb
tdiary-4.0.1.20130903 tdiary/rack/assets/precompile.rb
tdiary-4.0.1 tdiary/rack/assets/precompile.rb
tdiary-4.0.0.20130826 tdiary/rack/assets/precompile.rb
tdiary-4.0.0 tdiary/rack/assets/precompile.rb