Permalink
Browse files

Initial checkin

  • Loading branch information...
0 parents commit 8192972730fb7ab2c398832c650b48c734836a6a @jnicklas committed Jan 3, 2010
Showing with 209 additions and 0 deletions.
  1. +3 −0 History.txt
  2. +10 −0 Manifest.txt
  3. +48 −0 README.rdoc
  4. +15 −0 Rakefile
  5. +7 −0 app/controllers/bistro_car/bundle_controller.rb
  6. +3 −0 config/routes.rb
  7. +85 −0 lib/bistro_car.rb
  8. +10 −0 script/console
  9. +14 −0 script/destroy
  10. +14 −0 script/generate
3 History.txt
@@ -0,0 +1,3 @@
+=== 0.1 2010-01-03
+
+First release
10 Manifest.txt
@@ -0,0 +1,10 @@
+History.txt
+Manifest.txt
+README.rdoc
+Rakefile
+app/controllers/bistro_car/bundle_controller.rb
+config/routes.rb
+lib/bistro_car.rb
+script/console
+script/destroy
+script/generate
48 README.rdoc
@@ -0,0 +1,48 @@
+= bistro_car
+
+* http://github.com/#{github_username}/#{project_name}
+
+== DESCRIPTION:
+
+FIX (describe your package)
+
+== FEATURES/PROBLEMS:
+
+* FIX (list of features or problems)
+
+== SYNOPSIS:
+
+ FIX (code sample of usage)
+
+== REQUIREMENTS:
+
+* FIX (list of requirements)
+
+== INSTALL:
+
+* FIX (sudo gem install, anything else)
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2010 FIXME full name
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15 Rakefile
@@ -0,0 +1,15 @@
+require 'rubygems'
+gem 'hoe', '>= 2.1.0'
+require 'hoe'
+require 'fileutils'
+require './lib/bistro_car'
+
+Hoe.plugin :newgem
+
+Hoe.spec 'bistro_car' do
+ self.developer 'Jonas Nicklas', 'jonas.nicklas@gmail.com'
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
+ self.rubyforge_name = self.name # TODO this is default value
+ self.extra_deps = [['coffee-script','>= 0.1.6']]
+ self.version = BistroCar::VERSION
+end
7 app/controllers/bistro_car/bundle_controller.rb
@@ -0,0 +1,7 @@
+class BistroCar::BundleController < ActionController::Base
+ caches_page :show
+
+ def show
+ render :text => BistroCar::Bundle.new(params[:bundle]).to_javascript
+ end
+end
3 config/routes.rb
@@ -0,0 +1,3 @@
+ActionController::Routing::Routes.draw do |map|
+ map.connect 'javascripts/bundle/:bundle.js', :controller => 'bistro_car/bundle', :action => 'show'
+end
85 lib/bistro_car.rb
@@ -0,0 +1,85 @@
+require 'coffee-script'
+
+module BistroCar
+
+ VERSION = "0.1"
+
+ class Bundle
+ attr_reader :name
+
+ def initialize(name)
+ @name = name.to_sym
+ end
+
+ def file_paths
+ Dir.glob(path.join('*.coffee')).to_a
+ end
+
+ def render(mode)
+ __send__("render_#{mode}")
+ end
+
+ def to_javascript
+ file_paths.map { |path| CoffeeScript.compile(File.read(path)) }.join
+ end
+
+ private
+
+ def javascript_url
+ "/javascripts/bundle/#{name}.js"
+ end
+
+ def render_bundled
+ %(<script src="#{javascript_url}" type="text/javascript" charset="utf-8"></script>)
+ end
+
+ def render_inline
+ <<-HTML
+ <script type="text/javascript" charset="utf-8">
+ //<![CDATA[
+ #{to_javascript}
+ //]]>
+ </script>
+ HTML
+ end
+
+ def path
+ if name == :default
+ Rails.root.join('app/scripts')
+ else
+ Rails.root.join('app/scripts', name.to_s)
+ end
+ end
+ end
+
+
+ module Helpers
+ def coffee_script_bundle(*bundles)
+ [:default, *bundles].map { |name| Bundle.new(name).render(:bundled) }.join
+ end
+
+ def coffee_script(&block)
+ input = realign_indentation(capture(&block))
+ output = CoffeeScript.compile(input)
+
+ concat <<-HTML
+ <script type="text/javascript" charset="utf-8">
+ //<![CDATA[
+ #{output}
+ //]]>
+ </script>
+ HTML
+ end
+
+ private
+
+ def realign_indentation(string)
+ lines = string.split(/[\n\r]+/).select(&:present?)
+ basis = lines.first.index(/\S/) # find the first non-whitespace character
+ return lines.map { |s| s.sub(/^\s{#{basis}}/, '') }.join("\n")
+ end
+
+ end
+end
+
+ActionView::Base.send(:include, BistroCar::Helpers) if defined?(ActionView::Base)
10 script/console
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby
+# File: script/console
+irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
+
+libs = " -r irb/completion"
+# Perhaps use a console_lib to store any extra methods I may want available in the cosole
+# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
+libs << " -r #{File.dirname(__FILE__) + '/../lib/bistro_car.rb'}"
+puts "Loading bistro_car gem"
+exec "#{irb} #{libs} --simple-prompt"
14 script/destroy
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+begin
+ require 'rubigen'
+rescue LoadError
+ require 'rubygems'
+ require 'rubigen'
+end
+require 'rubigen/scripts/destroy'
+
+ARGV.shift if ['--help', '-h'].include?(ARGV[0])
+RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
+RubiGen::Scripts::Destroy.new.run(ARGV)
14 script/generate
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+begin
+ require 'rubigen'
+rescue LoadError
+ require 'rubygems'
+ require 'rubigen'
+end
+require 'rubigen/scripts/generate'
+
+ARGV.shift if ['--help', '-h'].include?(ARGV[0])
+RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
+RubiGen::Scripts::Generate.new.run(ARGV)

0 comments on commit 8192972

Please sign in to comment.