diff --git a/Gemfile b/Gemfile index 2c9777c8..711138c6 100644 --- a/Gemfile +++ b/Gemfile @@ -37,6 +37,8 @@ gem 'redcarpet' gem 'yard-sinatra', '1.0.0' gem 'stringex', '1.3.2' gem 'backports', '2.3.0' +gem 'coffee-script' +gem 'therubyracer' Dir["public/plugin/lokka-*/Gemfile"].each {|path| eval(open(path) {|f| f.read }) } diff --git a/Gemfile.lock b/Gemfile.lock index 3b290193..cce4b179 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,6 +40,10 @@ GEM builder (3.0.0) chunky_png (1.2.8) coderay (1.0.5) + coffee-script (2.2.0) + coffee-script-source + execjs + coffee-script-source (1.6.3) compass (0.12.2) chunky_png (~> 1.2) fssm (>= 0.2.7) @@ -83,6 +87,8 @@ GEM erubis (2.6.6) abstract (>= 1.0.0) eventmachine (1.0.3) + execjs (1.4.0) + multi_json (~> 1.0) expression_parser (0.9.0) factory_girl (2.6.1) activesupport (>= 2.3.9) @@ -95,6 +101,7 @@ GEM i18n (0.6.0) json (1.5.5) kramdown (1.0.2) + libv8 (3.11.8.17) multi_json (1.0.4) nokogiri (1.5.9) padrino-core (0.11.2) @@ -116,6 +123,7 @@ GEM rack (>= 1.0) rake (10.0.4) redcarpet (2.3.0) + ref (1.0.5) ripl (0.7.0) bond (~> 0.4.2) ripl-multi_line (0.3.1) @@ -157,6 +165,9 @@ GEM tapp (1.3.0) thor temple (0.3.5) + therubyracer (0.11.4) + libv8 (~> 3.11.8.12) + ref thor (0.17.0) tilt (1.3.7) tux (0.3.0) @@ -184,6 +195,7 @@ DEPENDENCIES builder (= 3.0.0) bundler coderay (= 1.0.5) + coffee-script compass data_objects! database_cleaner (= 0.7.1) @@ -221,6 +233,7 @@ DEPENDENCIES slim (~> 0.9.2) stringex (= 1.3.2) tapp (= 1.3.0) + therubyracer tux wikicloth (= 0.7.1) yard-sinatra (= 1.0.0) diff --git a/lib/lokka.rb b/lib/lokka.rb index 6faa786e..754213b8 100644 --- a/lib/lokka.rb +++ b/lib/lokka.rb @@ -123,6 +123,7 @@ def load_plugin(app) require 'sass' require 'compass' require 'slim' +require 'coffee-script' require 'builder' require 'nokogiri' require 'lokka/database' diff --git a/lib/lokka/app.rb b/lib/lokka/app.rb index da15b493..e5ec83e9 100644 --- a/lib/lokka/app.rb +++ b/lib/lokka/app.rb @@ -20,6 +20,7 @@ class App < Sinatra::Base set :theme => Proc.new { File.join(public_folder, 'theme') } set :supported_templates => %w(erb haml slim erubis) set :supported_stylesheet_templates => %w(scss sass) + set :supported_javascript_templates => %w(coffee) set :scss, Compass.sass_engine_options set :sass, Compass.sass_engine_options set :per_page, 10 @@ -71,6 +72,11 @@ class App < Sinatra::Base render_any path.to_sym, :views => settings.views end + get '/*.js' do |path| + content_type 'text/javascript', :charset => 'utf-8' + render_any path.to_sym, :views => settings.views + end + run! if app_file == $0 end end diff --git a/lib/lokka/helpers/render_helper.rb b/lib/lokka/helpers/render_helper.rb index 56083c7a..d08ffb4e 100644 --- a/lib/lokka/helpers/render_helper.rb +++ b/lib/lokka/helpers/render_helper.rb @@ -28,7 +28,8 @@ def partial(name, options = {}) def render_any(name, options = {}) ret = '' - templates = settings.supported_templates + settings.supported_stylesheet_templates + templates = settings.supported_templates + settings.supported_stylesheet_templates + + settings.supported_javascript_templates templates.each do |ext| out = rendering(ext, name, options) out.force_encoding(Encoding.default_external) unless out.nil? diff --git a/spec/integration/app_spec.rb b/spec/integration/app_spec.rb index 3b9babd0..9138e7b6 100644 --- a/spec/integration/app_spec.rb +++ b/spec/integration/app_spec.rb @@ -256,4 +256,25 @@ last_response.status.should == 200 end end + + context "when theme has coffee scripted js" do + before do + @file = 'public/theme/jarvi/script.coffee' + content =<<-EOS.strip_heredoc + console.log "Hello, It's me!" + EOS + open(@file, 'w') do |f| + f.write content + end + end + + after do + File.unlink(@file) + end + + it "should return compiled javascript" do + get '/theme/jarvi/script.js' + last_response.body.should == "(function() {\n console.log(\"Hello, It's me!\");\n\n}).call(this);\n" + end + end end