Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add more barista stuff

  • Loading branch information...
commit 02b7a2dcf0e9110b2e2ec9218173574e6e5591c4 1 parent 017bc18
@Sutto authored
View
15 README.md
@@ -0,0 +1,15 @@
+# Barista
+
+Barista is very, very similar to [bistro\_car](http://github.com/jnicklas/bistro_car) (infact, credit where credit is due - it shares similar
+code / is almost a fork).
+
+The main difference being, it lets you use coffee as you would javascript. Simply put, Write coffee
+and place it in `app/scripts` and Barista will automatically serve it as if it was placed in `public/javascripts`
+
+That is, `app/scripts/demo.coffee` will work for `/javascripts/demo.js`. Even better (and more importantly
+for me), it provides `Barista.compile_all!` which takes all coffee files and compiles them into `public/javascripts`.
+
+If you're using Jammit, this means you can simple run a rake task (`rake barista:brew` before running jammit) and
+your coffeescripts will be automatically provided, ready for bundling.
+
+Barista require rails 3+ (but patches for Rails 2 will be accepted.)
View
15 Rakefile
@@ -1,15 +1,18 @@
require 'rubygems'
require 'rake'
+require 'lib/barista/version'
+
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
- gem.name = "barista"
- gem.summary = %Q{TODO: one-line summary of your gem}
- gem.description = %Q{TODO: longer description of your gem}
- gem.email = "sutto@sutto.net"
- gem.homepage = "http://github.com/Sutto/barista"
- gem.authors = ["Darcy Laycock"]
+ gem.name = "barista"
+ gem.summary = %Q{Transparent coffeescript support for rails 3}
+ gem.description = %Q{Automatically compiles app/scripts/*.coffee to javascript for rails awesomesauce.}
+ gem.email = "sutto@sutto.net"
+ gem.homepage = "http://github.com/Sutto/barista"
+ gem.version = Barista::Version::STRING
+ gem.authors = ["Darcy Laycock"]
end
Jeweler::GemcutterTasks.new
rescue LoadError
View
4 app/controllers/barista_controller.rb
@@ -1,14 +1,14 @@
class BaristaController < ActionController::Base
- caches_page :show
+ caches_page :show if Rails.env.production?
def show
headers['Content-Type'] = "application/javascript"
path = normalize_path(params[:js_path])
+ p path
return head(:forbidden) unless can_render_path?(path)
compiled = Barista.render_path(path)
compiled.nil? ? head(:not_found) : render(:text => compiled.to_s)
- end
end
protected
View
46 barista.gemspec
@@ -0,0 +1,46 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{barista}
+ s.version = "0.1.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Darcy Laycock"]
+ s.date = %q{2010-04-24}
+ s.description = %q{TODO: longer description of your gem}
+ s.email = %q{sutto@sutto.net}
+ s.extra_rdoc_files = [
+ "LICENSE",
+ "README.rdoc"
+ ]
+ s.files = [
+ ".document",
+ ".gitignore",
+ "LICENSE",
+ "README.rdoc",
+ "Rakefile",
+ "app/controllers/barista_controller.rb",
+ "config/routes.rb",
+ "lib/barista.rb",
+ "lib/barista/compiler.rb"
+ ]
+ s.homepage = %q{http://github.com/Sutto/barista}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.6}
+ s.summary = %q{TODO: one-line summary of your gem}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ else
+ end
+ else
+ end
+end
+
View
2  config/routes.rb
@@ -1,3 +1,3 @@
Rails.application.routes.draw do
- match 'javascripts/*path.js', :to => 'barista#show'
+ match 'javascripts/*js_path.js', :to => 'barista#show'
end
View
11 lib/barista.rb
@@ -31,11 +31,11 @@ def render_path(path)
nil
end
- def compile_file!(file)
+ def compile_file!(file, force = false)
file = file.to_s
file = root.join(file).to_s unless file.include?(root.to_s)
- destination_path = file.gsub(/\.(coffee|js)\Z/, '') + ".js"
- return unless should_compile_file?(file, destination_path)
+ destination_path = file.gsub(/\.(coffee|js)\Z/, '').gsub(root.to_s, output_root.to_s) + ".js"
+ return unless force || should_compile_file?(file, destination_path)
File.open(destination_path, "w+") do |f|
f.write Compiler.compile(File.read(file))
end
@@ -48,8 +48,9 @@ def should_compile_file?(from, to)
File.exist?(from) && (!File.exist?(to) || File.mtime(to) < File.mtime(from))
end
- def compile_all!
- Dir[root.join("**", "*.coffee")].each {|file| compile_file! file }
+ def compile_all!(force = false)
+ Dir[root.join("**", "*.coffee")].each {|file| compile_file! file, force }
+ true
end
end
View
8 lib/barista/tasks/barista.rake
@@ -0,0 +1,8 @@
+namespace :barista do
+
+ desc "Compiles coffeescripts from app/scripts into public/javascripts"
+ task :brew => :environment do
+ Barista.compile_all!(true)
+ end
+
+end
View
8 lib/barista/version.rb
@@ -0,0 +1,8 @@
+module Barista
+ module Version
+ MAJOR = 0
+ MINOR = 1
+ PATCH = 0
+ STRING = [MAJOR, MINOR, PATCH].join(".")
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.