coffee-cup 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in coffee-cup.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 De Marque inc.
2
+
3
+ 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:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ 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.
data/README.md ADDED
@@ -0,0 +1,118 @@
1
+ Coffee Cup
2
+ ===============
3
+
4
+ Coffee Cup set the foundations of a Rails like structure for your all your CoffeeScript code.
5
+
6
+ Problem
7
+ -------
8
+
9
+ There's currently no convention to structure the CoffeeScript code. The directory /assets/javascripts
10
+ can quickly become a mess and after a while it become really hard to identify which file are used in
11
+ which context.
12
+
13
+ This is where Coffee Cup is coming to the rescue !
14
+
15
+ It provide a standardize CoffeeScript structure mirror on the rails directories. For each view, you'll
16
+ exactly know what CoffeeScript dependency it has.
17
+
18
+ Install
19
+ -------
20
+
21
+ ```
22
+ gem install coffee-cup
23
+ ```
24
+
25
+ Rails 3
26
+ -------
27
+
28
+ In your Gemfile:
29
+
30
+ ```ruby
31
+ gem 'coffee-cup'
32
+ ```
33
+
34
+ Coffee Cup rely on a data attribute inside the body tag to indicate the current controller and action.
35
+ It is required to add to your body tag the following code :
36
+
37
+ ```ruby
38
+ content_tag(:body, "data-coffee-cup" => CoffeeCup.body_data(request)) do
39
+ # Layout
40
+ end
41
+
42
+ ```
43
+
44
+ Usage
45
+ -----
46
+
47
+ Coffee Cup is mainly a directory convention to store your CoffeeScript.
48
+
49
+ ### Basic File Structure
50
+
51
+ You must first create the following directories :
52
+
53
+
54
+ ```
55
+ # In app/assets/javascripts/
56
+ app
57
+ |--- helpers
58
+ |--- application_helpers.coffee
59
+ |--- views
60
+
61
+ ```
62
+
63
+ ### Helpers
64
+
65
+ In the application_helpers.coffee
66
+
67
+ ```coffeescript
68
+ @module "ApplicationHelper", ->
69
+ @initialize = ->
70
+ ```
71
+
72
+ The code in the initialize will be loaded first. You can place all the global helpers of your application
73
+ in this directory and initialize them from the ApplicationHelper#initialize method.
74
+
75
+ ### Views
76
+
77
+ Inside the views directory, you will place the code for each view. For example, if you have specific code
78
+ for the users_controller#show, you will create the following file.
79
+
80
+ ```coffeescript
81
+ # /app/assets/javascripts/app/views/users/show.coffee
82
+ @view "Users.Show",
83
+ constructor: -> # Insert your code for the Users Show action.
84
+ ```
85
+
86
+ This code will only be executed when the Users Show action is called.
87
+
88
+ ### Partials
89
+
90
+ Sometimes the same block of codes need to be shared between differents actions. To solve this situation,
91
+ you have access to a ```render``` method.
92
+
93
+ For example, if you need the same code inside the Users New and Edit, let's say for a form. You could do
94
+ the following :
95
+
96
+ ```coffeescript
97
+ # /app/assets/javascripts/app/views/users/new.coffee
98
+ @view "Users.New",
99
+ constructor: -> @render 'users/form'
100
+ ```
101
+
102
+ ```coffeescript
103
+ # /app/assets/javascripts/app/views/users/edit.coffee
104
+ @view "Users.Edit",
105
+ constructor: -> @render 'users/form'
106
+ ```
107
+
108
+ ```coffeescript
109
+ # /app/assets/javascripts/app/views/users/_form.coffee
110
+ @view "Users.Form",
111
+ constructor: -> # This code will be shared between the New and Edit actions.
112
+ ```
113
+
114
+
115
+ Copyright
116
+ ---------
117
+
118
+ Copyright (c) 2012 De Marque inc. See LICENSE for further details.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,19 @@
1
+ @module = (names, fn) ->
2
+ names = names.split '.' if typeof names is 'string'
3
+ space = @[names.shift()] ||= {}
4
+ space.module ||= @module
5
+ if names.length
6
+ space.module names, fn
7
+ else
8
+ fn.call space
9
+
10
+
11
+ @view = (names, obj) ->
12
+ names = names.split '.'
13
+ className = names[names.length - 1]
14
+ namespace = names[0..names.length-2]
15
+
16
+ @module "Views.#{namespace.join('.')}", ->
17
+ @[className] = class extends ActionView
18
+ if obj.constructor then constructor: obj.constructor
19
+ @::[key] = value for key, value of obj when key isnt 'constructor'
@@ -0,0 +1,23 @@
1
+ #*************************************************************************************
2
+ # Application Controller
3
+ #*************************************************************************************
4
+ class ApplicationController
5
+ #*************************************************************************************
6
+ # PUBLIC INSTANCE METHODS
7
+ #*************************************************************************************
8
+ loadHelpers: -> ApplicationHelper.initialize()
9
+
10
+ loadView: ->
11
+ if $('body').data('coffee-cup')
12
+ CoffeeCup.renderView $('body').data('coffee-cup').split('#').join('.')
13
+ else
14
+ alert 'Coffee Cup : Installation incomplete. Please insert the body attribute "data-coffee-cup". See documentation for more details.'
15
+
16
+
17
+ #*************************************************************************************
18
+ # When the document is ready, it will load the appropriate objects
19
+ #*************************************************************************************
20
+ $ ->
21
+ controller = new ApplicationController
22
+ controller.loadHelpers()
23
+ controller.loadView()
@@ -0,0 +1,14 @@
1
+ @module "CoffeeCup", ->
2
+ @camelize = (str) ->
3
+ str = str.toLowerCase()
4
+ str = (part.charAt(0).toUpperCase() + part.slice(1) for part in str.split('/')).join('.')
5
+ str = (part.charAt(0).toUpperCase() + part.slice(1) for part in str.split('_')).join('')
6
+
7
+ return str
8
+
9
+
10
+ @renderView = (path) ->
11
+ instanceName = CoffeeCup.camelize($('body').data('instance'))
12
+
13
+ try eval("new Views.#{path}")
14
+ try eval("new Views.#{instanceName}.#{path}")
@@ -0,0 +1,4 @@
1
+ //= require ./base
2
+ //= require ./helpers
3
+ //= require_tree ./controllers
4
+ //= require_tree ./views
@@ -0,0 +1,27 @@
1
+ @module "ApplicationHelper", ->
2
+
3
+ class @ActionView
4
+ #*************************************************************************************
5
+ # ALIASES
6
+ #*************************************************************************************
7
+ h: ApplicationHelper
8
+
9
+
10
+ #*************************************************************************************
11
+ # PUBLIC INSTANCE METHODS
12
+ #*************************************************************************************
13
+ loadPartial: (url, callback, rootTag = '') ->
14
+ if url.indexOf('?') > 0 then url += '&layout=none' else url += '?layout=none'
15
+
16
+ $.get(url, (data) => @receivePartial(data, callback, rootTag))
17
+
18
+
19
+ locale: () -> $('meta[name="content-language"]').attr('content')
20
+
21
+
22
+ receivePartial: (data, callback, rootTag) ->
23
+ partial = $('<div>' + data + '</div>').find(rootTag).html()
24
+
25
+ callback partial
26
+
27
+ render: (path) -> CoffeeCup.renderView CoffeeCup.camelize(path)
@@ -0,0 +1,5 @@
1
+ module CoffeeCup
2
+ class Engine < Rails::Engine
3
+ #auto wire
4
+ end
5
+ end
data/lib/coffee-cup.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "coffee-cup/engine"
2
+
3
+ module CoffeeCup
4
+ def self.body_data(request)
5
+ request[:controller].camelize + '#' + request[:action].camelize
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe CoffeeCup do
4
+
5
+ end
@@ -0,0 +1,12 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
4
+ require 'rspec'
5
+
6
+ require File.expand_path('../../lib/coffee-cup', __FILE__)
7
+
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
9
+
10
+ RSpec.configure do |config|
11
+ config.mock_with :rspec
12
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coffee-cup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sebastien Rosa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &2151892760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.7
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2151892760
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &2151891960 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2151891960
36
+ - !ruby/object:Gem::Dependency
37
+ name: metrical
38
+ requirement: &2151890920 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 0.1.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2151890920
47
+ description: Coffee Cup set the foundations of a Rails like structure for your all
48
+ your CoffeeScript code.
49
+ email:
50
+ - sebastien@demarque.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files:
54
+ - LICENSE
55
+ - README.md
56
+ files:
57
+ - app/assets/javascripts/coffee_cup/base.coffee
58
+ - app/assets/javascripts/coffee_cup/controllers/application_controller.coffee
59
+ - app/assets/javascripts/coffee_cup/helpers.coffee
60
+ - app/assets/javascripts/coffee_cup/index.js
61
+ - app/assets/javascripts/coffee_cup/views/base.coffee
62
+ - lib/coffee-cup/engine.rb
63
+ - lib/coffee-cup.rb
64
+ - spec/coffee-cup_spec.rb
65
+ - spec/spec_helper.rb
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - Gemfile
70
+ homepage: https://github.com/demarque/coffee-cup
71
+ licenses:
72
+ - MIT
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project: coffee-cup
91
+ rubygems_version: 1.8.17
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Coffee Cup set the foundations of a Rails like structure for your all your
95
+ CoffeeScript code.
96
+ test_files: []