coffeekupper 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.gitignore +19 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +22 -0
  5. data/README.md +103 -0
  6. data/Rakefile +8 -0
  7. data/coffeekupper.gemspec +22 -0
  8. data/lib/coffeekupper.rb +5 -0
  9. data/lib/coffeekupper/engine.rb +17 -0
  10. data/lib/coffeekupper/template.rb +28 -0
  11. data/lib/coffeekupper/version.rb +3 -0
  12. data/spec/dummy/Rakefile +7 -0
  13. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  14. data/spec/dummy/app/assets/javascripts/sample.js.coffeekup +6 -0
  15. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  16. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  17. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  18. data/spec/dummy/app/mailers/.gitkeep +0 -0
  19. data/spec/dummy/app/models/.gitkeep +0 -0
  20. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  21. data/spec/dummy/config.ru +4 -0
  22. data/spec/dummy/config/application.rb +65 -0
  23. data/spec/dummy/config/boot.rb +10 -0
  24. data/spec/dummy/config/database.yml +25 -0
  25. data/spec/dummy/config/environment.rb +5 -0
  26. data/spec/dummy/config/environments/development.rb +37 -0
  27. data/spec/dummy/config/environments/production.rb +67 -0
  28. data/spec/dummy/config/environments/test.rb +37 -0
  29. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  30. data/spec/dummy/config/initializers/inflections.rb +15 -0
  31. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  32. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  33. data/spec/dummy/config/initializers/session_store.rb +8 -0
  34. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  35. data/spec/dummy/config/locales/en.yml +5 -0
  36. data/spec/dummy/config/routes.rb +58 -0
  37. data/spec/dummy/lib/assets/.gitkeep +0 -0
  38. data/spec/dummy/log/.gitkeep +0 -0
  39. data/spec/dummy/public/404.html +26 -0
  40. data/spec/dummy/public/422.html +26 -0
  41. data/spec/dummy/public/500.html +25 -0
  42. data/spec/dummy/public/favicon.ico +0 -0
  43. data/spec/dummy/script/rails +6 -0
  44. data/spec/spec_helper.rb +11 -0
  45. data/spec/support/assets.rb +9 -0
  46. data/spec/support/dom.rb +9 -0
  47. data/spec/support/sprockets.rb +17 -0
  48. data/spec/support/templates/hello.jst.coffeekup +1 -0
  49. data/spec/template_spec.rb +61 -0
  50. data/vendor/assets/javascripts/coffee-script.js +8 -0
  51. data/vendor/assets/javascripts/coffeekup.js +427 -0
  52. metadata +198 -0
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rvmrc
19
+ *.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in coffeekupper.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Zohar Arad
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,103 @@
1
+ # CoffeeKupper
2
+
3
+ CoffeeKupper is a CoffeeKup template parser for Rails Asset-Pipeline. With CoffeeKupper you can write CoffeeKup templates
4
+ in your Rails app, and serve them via your asset pipeline.
5
+
6
+ CoffeeKupper is just a wrapper around CoffeeKup that breaks your template file into a string that is then fed into the `CoffeeKup.compile` method.
7
+ This means you can use your CoffeeKupper templates as you would use any CoffeeKup template.
8
+
9
+ You should check out the [CoffeeKup Website](http://coffeekup.org) for more details on how to use CoffeeKup.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'coffeekupper'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install coffeekupper
24
+
25
+ ## Usage
26
+
27
+ ### Basic Concepts
28
+
29
+ The best way to use CoffeeKup templates (powered by CoffeeKupper), is to write them as JST files. In case you're not familiar with
30
+ Sprockets' JST, by adding a `.jst` extention to your Javascript files, Sprockets will serve them in a special way, that will make each
31
+ file available under the global JST object. Think of it as a global way to access encapsulated templates.
32
+
33
+ To serve a CoffeeKup template from Rails, lets assume you have a `views` directory under `app/assets/javascripts`. Add a
34
+ CoffeeKup template file to that directory and give it a name (for example, name your file `my_first_view.jst.ck`). Note the
35
+ addition of `.jst` before the `.ck` file extension. This will tell Sprockets to add the template to the global JST object.
36
+
37
+ Now, add a bit of CoffeeKup code. Maybe something along the lines of:
38
+ ```coffeescript
39
+ h1 -> 'Hello CoffeKupper'
40
+ p ->
41
+ 'I would love to hear some more from you'
42
+ ```
43
+
44
+ If you point your browser to `http://localhost:3000/assets/views/my_first_view.js` you'll see the JST version of your template.
45
+
46
+ Sweet, right?
47
+
48
+ ### Adding to the asset pipeline
49
+
50
+ To actually use the template in your app, add the following lines to your `application.js` (or any other Javascript file that has been added to the Asset Pipeline):
51
+
52
+ ```
53
+ //browser version of CoffeeScript (available from CoffeeKupper vendor/assets)
54
+ //= require coffee-script
55
+ //browser version of CoffeeKup (available from CoffeeKupper vendor/assets)
56
+ //= require coffeekup
57
+ //= require_tree ./views
58
+ ```
59
+
60
+ When you actually want to render your template from another Javascript file, simply call:
61
+
62
+ ```javascript
63
+ var html = JST['views/my_first_view']()
64
+ ```
65
+
66
+ ### Passing template variables
67
+
68
+ Passing variables to your template is easy. Just add them as an object to the template call.
69
+
70
+ Assumming we have the following CoffeeKup template:
71
+
72
+ ```coffeescript
73
+ header ->
74
+ h1 -> @title
75
+ h2 -> @subtitle
76
+ p ->
77
+ @text
78
+ ```
79
+
80
+ We can pass the right variables to the template like this:
81
+
82
+ ```javascript
83
+ var html = JST['views/my_first_view']({title:"Some title", subtitle:"Some subtitle", text:"Some text"})
84
+ ```
85
+
86
+
87
+ ## Contributing
88
+
89
+ 1. Fork it
90
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
91
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
92
+ 4. Push to the branch (`git push origin my-new-feature`)
93
+ 5. Create new Pull Request
94
+
95
+ ## License
96
+
97
+ Copyright (c) 2012 Zohar Arad <zohar@zohararad.com>
98
+
99
+ 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:
100
+
101
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
102
+
103
+ 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.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ # If you want to make this the default task
8
+ task :default => :spec
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/coffeekupper/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Zohar Arad"]
6
+ gem.email = ["zohar@zohararad.com"]
7
+ gem.description = %q{CoffeeKup compiler for Asset Pipeline}
8
+ gem.summary = %q{Write client side templates in Rails using CoffeeKup}
9
+ gem.homepage = "https://github.com/zohararad/coffeekupper"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "coffeekupper"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Coffeekupper::VERSION
17
+
18
+ gem.add_dependency 'sprockets', '>= 2.1.3'
19
+ gem.add_development_dependency 'therubyracer'
20
+ gem.add_development_dependency 'rspec'
21
+ gem.add_development_dependency 'rails', '>= 3.1.1'
22
+ end
@@ -0,0 +1,5 @@
1
+ require "coffeekupper/template"
2
+ require "coffeekupper/engine" if defined?(::Rails)
3
+
4
+ module Coffeekupper
5
+ end
@@ -0,0 +1,17 @@
1
+ module Coffeekupper
2
+
3
+ class Engine < Rails::Engine
4
+
5
+ initializer "coffeekupper.configure_rails_initialization", :before => 'sprockets.environment', :group => :all do |app|
6
+ next unless app.config.assets.enabled
7
+
8
+ require 'sprockets'
9
+ require 'sprockets/engines'
10
+ require 'coffeekupper/template'
11
+ Sprockets.register_engine '.coffeekup', ::Coffeekupper::Template
12
+ Sprockets.register_engine '.ck', ::Coffeekupper::Template
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,28 @@
1
+ require 'tilt/template'
2
+
3
+ module Coffeekupper
4
+
5
+ class Template < Tilt::Template
6
+
7
+ self.default_mime_type = 'application/javascript'
8
+
9
+ def prepare
10
+ end
11
+
12
+ def evaluate(scope, locals, &block)
13
+ %( (function(){ var tmpl = #{template_as_string(data)}; return CoffeeKup.compile(tmpl) })() )
14
+ end
15
+
16
+ private
17
+
18
+ # Splits a CoffeeKup template into lines joined by "+" sign
19
+ # so the template text can be properly fed into the CoffeeKup compiler as a
20
+ # concatenation of Javascript strings
21
+ # @param [String] template the template to split
22
+ # @return [String] split template as concatenation of Javascript strings
23
+ def template_as_string(template)
24
+ template.split("\n").collect{|line| '"' + line.gsub(/\"/,'\\"') + '"' }.join('+'+'"\n"'+'+')
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Coffeekupper
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,6 @@
1
+ h1 ->
2
+ 'Hello World'
3
+ p ->
4
+ 'Some Text For Hello'
5
+ for i in [1,2,3,4,5]
6
+ p -> "#{i}"
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", :media => "all" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,65 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_mailer/railtie"
7
+ require "active_resource/railtie"
8
+ require "sprockets/railtie"
9
+ # require "rails/test_unit/railtie"
10
+
11
+ Bundler.require
12
+ require "coffeekupper"
13
+
14
+ module Dummy
15
+ class Application < Rails::Application
16
+ # Settings in config/environments/* take precedence over those specified here.
17
+ # Application configuration should go into files in config/initializers
18
+ # -- all .rb files in that directory are automatically loaded.
19
+
20
+ # Custom directories with classes and modules you want to be autoloadable.
21
+ # config.autoload_paths += %W(#{config.root}/extras)
22
+
23
+ # Only load the plugins named here, in the order given (default is alphabetical).
24
+ # :all can be used as a placeholder for all plugins not explicitly named.
25
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
26
+
27
+ # Activate observers that should always be running.
28
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
29
+
30
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
31
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
32
+ # config.time_zone = 'Central Time (US & Canada)'
33
+
34
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
35
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
36
+ # config.i18n.default_locale = :de
37
+
38
+ # Configure the default encoding used in templates for Ruby 1.9.
39
+ config.encoding = "utf-8"
40
+
41
+ # Configure sensitive parameters which will be filtered from the log file.
42
+ config.filter_parameters += [:password]
43
+
44
+ # Enable escaping HTML in JSON.
45
+ config.active_support.escape_html_entities_in_json = true
46
+
47
+ # Use SQL instead of Active Record's schema dumper when creating the database.
48
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
49
+ # like if you have constraints or database-specific column types
50
+ # config.active_record.schema_format = :sql
51
+
52
+ # Enforce whitelist mode for mass assignment.
53
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
54
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
55
+ # parameters by using an attr_accessible or attr_protected declaration.
56
+ config.active_record.whitelist_attributes = true
57
+
58
+ # Enable the asset pipeline
59
+ config.assets.enabled = true
60
+
61
+ # Version of your assets, change this if you want to expire all your assets
62
+ config.assets.version = '1.0'
63
+ end
64
+ end
65
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,37 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+
25
+ # Raise exception on mass assignment protection for Active Record models
26
+ config.active_record.mass_assignment_sanitizer = :strict
27
+
28
+ # Log the query plan for queries taking more than this (works
29
+ # with SQLite, MySQL, and PostgreSQL)
30
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
31
+
32
+ # Do not compress assets
33
+ config.assets.compress = false
34
+
35
+ # Expands the lines which load the assets
36
+ config.assets.debug = true
37
+ end