Skip to content

Commit

Permalink
Merge pull request lokka#186 from morygonzalez/support-coffee-script
Browse files Browse the repository at this point in the history
CoffeeScript で JavaScript を書きたい / Support CoffeeScript
  • Loading branch information
komagata committed Jul 30, 2013
2 parents ee002ce + 9417ea4 commit 002a0af
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -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 }) }

Expand Down
13 changes: 13 additions & 0 deletions Gemfile.lock
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -184,6 +195,7 @@ DEPENDENCIES
builder (= 3.0.0)
bundler
coderay (= 1.0.5)
coffee-script
compass
data_objects!
database_cleaner (= 0.7.1)
Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions lib/lokka.rb
Expand Up @@ -123,6 +123,7 @@ def load_plugin(app)
require 'sass'
require 'compass'
require 'slim'
require 'coffee-script'
require 'builder'
require 'nokogiri'
require 'lokka/database'
Expand Down
6 changes: 6 additions & 0 deletions lib/lokka/app.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion lib/lokka/helpers/render_helper.rb
Expand Up @@ -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?
Expand Down
21 changes: 21 additions & 0 deletions spec/integration/app_spec.rb
Expand Up @@ -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

0 comments on commit 002a0af

Please sign in to comment.