joosy-rails 1.0.0.beta.3 → 1.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b2eb276dba4ba52a0f07fd9ce7b54c5dac0fb16
4
- data.tar.gz: 9d2ff2dffd645a45633d82dde243ad940c500e86
3
+ metadata.gz: 3f4c956ac6c811912d2f3fd84fc5237b405a592f
4
+ data.tar.gz: 88f62c939a0903964f9607968d03607d4cba0a12
5
5
  SHA512:
6
- metadata.gz: 7110bebfcfd0081fdebd9a689c443e916ebb7dc2b37100603ec8a51d63e74a2967cec2bdba33388e84aaf9315bb935d6254371e961b7b81cdbcc47df93753c36
7
- data.tar.gz: 49e48f5fec8edb14e302b1bc7056479dc2e676aff95edee4783cdd2d3d4591aa4f4ee12bdd81e5b102068785c70d73538103c419c2f68a9dbcc50e8d24504e18
6
+ metadata.gz: 5e40e76c5deaac35836fee232ab625f90bc784398a1e6d516a45433ad4324cc7d596a2b801b7cc278b254c42abbe5fa8702dfb575d4959f3b9124ca9097b96d2
7
+ data.tar.gz: 51f2f98722e649e45fa3ad9e6dfa7e907cf29884154c4e0241ab69bef8ed9c82bf639e7ec9c3e58310638766d2e9a9e175e7c090ef1eab14be7e7f54584fd8b2
data/README.md CHANGED
@@ -1,18 +1,21 @@
1
1
  # Joosy::Rails
2
2
 
3
- ![Joosy](http://f.cl.ly/items/2N2J453J2B353F1A0t0I/joocy1.1.png)
4
-
5
- Rails ties for the [Joosy](http://joosy.ws) Framework
3
+ <a href="http://joosy.ws"><img src="http://f.cl.ly/items/3X0f2K1z3r1X3K162W2c/logo.png" align="right" /></a>
6
4
 
7
5
  [![Gem Version](https://badge.fury.io/rb/joosy-rails.png)](http://badge.fury.io/rb/joosy-rails)
8
- [![Dependency Status](https://gemnasium.com/joosy/rails.png)](https://gemnasium.com/joosy/rails)
6
+ [![Dependency Status](https://gemnasium.com/joosy/joosy-rails.png)](https://gemnasium.com/joosy/joosy-rails)
7
+
8
+ The bindings between **[Joosy](http://joosy.ws) framework** and [Rails](http://rubyonrails.org).
9
+
10
+ If you are seeking for information about Joosy, start with [official site](http://joosy.ws), [guides](http://guides.joosy.ws) or [central repository](https://github.com/joosy/joosy/).
9
11
 
10
- On the menu:
12
+ ## Capabilities
11
13
 
12
14
  * Full assets integration
13
15
  * Generators
14
16
  * Built-in serving controller
15
17
  * Routes helpers
18
+ * Automatic Joosy Resources generation
16
19
 
17
20
  ## Installation
18
21
 
@@ -28,20 +31,35 @@ And then execute:
28
31
 
29
32
  ### Generators
30
33
 
31
- * `rails g joosy:application :name` – generates basic application and patches routes to make it loadable straight away.<br>
32
- **:name** can (and in most cases should) be ommited.<br>
34
+ #### rails g joosy:application (NAME)
35
+
36
+ Generates basic application and patches route to make it loadable straight away.
37
+
38
+ By default an application will be generated directly at `app/assets/javascripts`. If you want to isolate it a bit more, pass in the `NAME` argument &mdash; then it will appear at `app/assets/javascripts/NAME`.
39
+
40
+ #### rails g joosy:layout NAME (APPLICATION)
41
+
42
+ Generates Joosy layout. `NAME` can contain slashes to automatically generate corresponding path and namespace.
43
+
44
+ Note that if the application was initially generated with the usage of `NAME` option, you should pass it here as the second parameter (APPLICATION).
45
+
46
+ #### rails g joosy:page NAME (APPLICATION)
47
+
48
+ Generates Joosy page. `NAME` can contain slashes to automatically generate corresponding path and namespace.
33
49
 
34
- * `rails g joosy:layout :name (:application)` generates new `Joosy.Layout`.<br>
35
- **:name** can include any namespace (i.e. 'deeply/nested/layout').<br>
36
- **:application** is a name of an application.<br>
50
+ Note that if the application was initially generated with the usage of `NAME` option, you should pass it here as the second parameter (APPLICATION).
37
51
 
38
- * `rails g joosy:page :name (:application)` – generates new `Joosy.Page`.<br>
39
- **:name** can include any namespace (i.e. 'deeply/nested/page').<br>
40
- **:application** is a name of an application.<br>
52
+ #### rails g joosy:widget NAME (APPLICATION)
41
53
 
42
- * `rails g joosy:widget :name (:application)` generates new `Joosy.Widget`.<br>
43
- **:name** can include any namespace (i.e. 'deeply/nested/widget').<br>
44
- **:application** is a name of an application.
54
+ Generates Joosy widget. `NAME` can contain slashes to automatically generate corresponding path and namespace.
55
+
56
+ Note that if the application was initially generated with the usage of `NAME` option, you should pass it here as the second parameter (APPLICATION).
57
+
58
+ #### rails g joosy:controller NAME (--copy)
59
+
60
+ Generates a controller serving Joosy application using the NAME given.
61
+
62
+ By default a controller will inherit from internal `Joosy::Rails::ServeController`. If instead you want to patch it from the ground, use `--copy` option that will make generator to create raw controller that inherits from `ActionController::Base`.
45
63
 
46
64
  ### Serving controller and helpers
47
65
 
@@ -51,12 +69,18 @@ This gem provides `joosy` routing helper which can be used in the following way:
51
69
  joosy '/', application: 'dummy'
52
70
  ```
53
71
 
54
- This will map your `dummy` Joosy application to the root url. Note that `application` option is optional and can be ommited just like `:name` option of the application generator.
72
+ This will map your `dummy` Joosy application to the root url. The `application` option is optional. It should reflect path to application from `app/assets/javascript` (use the value that you passed into the NAME of `rails g joosy:application`).
73
+
74
+ ## Maintainers
75
+
76
+ * Boris Staal, [@inossidabile](http://staal.io)
77
+
78
+ ## License
79
+
80
+ Copyright 2013 [Boris Staal](http://staal.io)
81
+
82
+ It is free software, and may be redistributed under the terms of MIT license.
83
+
55
84
 
56
- ## Contributing
85
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/joosy/joosy-rails/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
57
86
 
58
- 1. Fork it
59
- 2. Create your feature branch (`git checkout -b my-new-feature`)
60
- 3. Commit your changes (`git commit -am 'Add some feature'`)
61
- 4. Push to the branch (`git push origin my-new-feature`)
62
- 5. Create new Pull Request
@@ -0,0 +1,13 @@
1
+ #= require ./resource_loader
2
+
3
+ <%
4
+ Joosy::Rails::Engine.route_dependencies.each do |path|
5
+ depend_on path
6
+ end
7
+ %>
8
+
9
+ routes = <%= Joosy::Rails::Engine.resources.to_json %>
10
+
11
+ Joosy.ResourceLoader.loadResources routes
12
+
13
+
@@ -0,0 +1,37 @@
1
+ #= require joosy/resources
2
+
3
+ Joosy.ResourceLoader =
4
+ defineResource: (name, path, parent) ->
5
+ class @[name] extends parent
6
+ @entity inflection.underscore(name)
7
+ @source path
8
+
9
+ namespaceFromLevels: (levels) ->
10
+ levels.map((x) ->
11
+ res = x.replace(/^\//, '').split('/')
12
+ if res.length > 1
13
+ # resource, has second (mask) part
14
+ res = inflection.singularize(res[0])
15
+ else
16
+ # scope
17
+ res = res[0]
18
+ inflection.camelize res
19
+ ).join('.')
20
+
21
+ loadResources: (routes) ->
22
+ for route in routes
23
+ levels = route.match /\/[^\/]+(\/:[^\/]+)?/g
24
+ continue unless levels instanceof Array
25
+ rootPath = levels.pop()
26
+ name = inflection.camelize inflection.singularize(rootPath.replace(/^\//, ''))
27
+
28
+ parent = if window[name] && Joosy.Module.hasAncestor(window[name], Joosy.Resources.REST)
29
+ window[name]
30
+ else if !window[name]
31
+ @defineResource.call window, name, rootPath, Joosy.Resources.REST
32
+ else
33
+ Joosy.Resources.REST
34
+
35
+ if (ns = @namespaceFromLevels(levels)) != ''
36
+ Joosy.namespace ns, ->
37
+ Joosy.ResourceLoader.defineResource.call @, name, route, parent
data/joosy-rails.gemspec CHANGED
@@ -18,10 +18,11 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'joosy', '>= 1.2.0.alpha.48'
21
+ spec.add_dependency 'joosy', '>= 1.2.0.beta.4'
22
22
  spec.add_dependency 'sprockets'
23
23
  spec.add_dependency 'execjs'
24
- spec.add_dependency 'ejs'
24
+ spec.add_dependency 'activesupport'
25
+ spec.add_dependency 'thor'
25
26
 
26
27
  spec.add_dependency 'sugar-rails'
27
28
  spec.add_dependency 'jquery-form-rails'
data/lib/joosy/rails.rb CHANGED
@@ -5,4 +5,5 @@ require 'joosy'
5
5
 
6
6
  require 'joosy/rails/version'
7
7
  require 'joosy/rails/controller'
8
- require 'joosy/rails/engine'
8
+ require 'joosy/rails/engine'
9
+ require 'joosy/rails/routing'
@@ -3,26 +3,22 @@ require 'rails/engine'
3
3
  module Joosy
4
4
  module Rails
5
5
  class Engine < ::Rails::Engine
6
+ cattr_accessor :resources
7
+ self.resources = []
8
+
6
9
  initializer 'joosy.extend.sprockets' do |app|
7
10
  Joosy.assets_paths.each{|p| app.assets.append_path p}
8
11
  end
9
- end
10
- end
11
- end
12
12
 
13
- module ActionDispatch::Routing
14
- class Mapper
15
- def joosy(route, options={})
16
- extender = route.last == '/' ? '(*x)' : '(/*x)'
13
+ initializer 'joosy.routing' do |app|
14
+ app.routes.prepend do
15
+ Engine.resources = []
16
+ end
17
+ end
17
18
 
18
- match route,
19
- controller: options[:controller] || 'joosy/rails/serve',
20
- action: options[:action] || 'index',
21
- via: :get,
22
- as: (options[:application] ? "joosy_#{options[:application]}" : "joosy"),
23
- defaults: {route: route, application: options[:application]},
24
- anchor: false,
25
- format: false
19
+ def route_dependencies
20
+ ::Rails.application.routes_reloader.paths
21
+ end
26
22
  end
27
23
  end
28
- end
24
+ end
@@ -0,0 +1,41 @@
1
+ require 'action_dispatch/routing/mapper'
2
+
3
+ module ActionDispatch::Routing
4
+ class Mapper
5
+ module Resources
6
+ class JoosyResource
7
+ def initialize(context)
8
+ @context = context
9
+ end
10
+
11
+ def method_missing(name, *args, &block)
12
+ @context.send(name, *args, &block)
13
+ end
14
+
15
+ def resources(*args, &block)
16
+ @context.resources(*args) do
17
+ scope = @context.instance_eval { @scope }
18
+ Joosy::Rails::Engine.resources << "#{scope[:path]}/#{scope[:scope_level_resource].path}"
19
+ @context.joosy_resources(&block)
20
+ end
21
+ end
22
+ end
23
+
24
+ def joosy_resources(&block)
25
+ JoosyResource.new(self).instance_eval(&block) if block_given?
26
+ end
27
+ end
28
+
29
+ def joosy(route, options={})
30
+ extender = route.last == '/' ? '(*x)' : '(/*x)'
31
+
32
+ get route,
33
+ controller: options[:controller] || 'joosy/rails/serve',
34
+ action: options[:action] || 'index',
35
+ as: (options[:application] ? "joosy_#{options[:application]}" : "joosy"),
36
+ defaults: {route: route, application: options[:application]},
37
+ anchor: false,
38
+ format: false
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  module Joosy
2
2
  module Rails
3
- VERSION = "1.0.0.beta.3"
3
+ VERSION = "1.0.0.rc4"
4
4
  end
5
5
  end
@@ -7,14 +7,21 @@ module Joosy
7
7
 
8
8
  def create_application
9
9
  dependencies = <<-COFFEE
10
+ #= require hamlcoffee
10
11
  #= require jquery
11
- #= require jquery.form
12
+ #= require joosy
13
+ #= require joosy/resources
14
+ #= require joosy/railties
12
15
  #= require sugar
13
- #= require hamlcoffee
14
16
  COFFEE
15
17
 
16
- self.destination_root = ::Rails.root.join('app/assets/javascripts/').join(name || '')
17
- run Joosy::Generators.pregenerate('project/base', {enableHTML5: true, templaterPrefix: name, dependencies: dependencies})
18
+ @options = {
19
+ 'dependencies' => dependencies,
20
+ 'html5' => true,
21
+ 'prefix' => name || ''
22
+ }
23
+
24
+ directory 'application', Pathname.new('app/assets/javascripts/').join(name || '')
18
25
  end
19
26
 
20
27
  def create_bindings
@@ -24,14 +31,14 @@ module Joosy
24
31
  index = ::Rails.root.join('app/assets/javascripts/application.js')
25
32
 
26
33
  if File.exists?(index)
27
- copy_file index, 'app/assets/javascripts/application.bak'
34
+ copy_file index, 'app/assets/javascripts/application.js-old'
28
35
  remove_file index
29
36
  end
30
37
  end
31
38
 
32
39
  layout = 'joosy'
33
40
  layout << "/#{name}" if name
34
- template File.expand_path('../templates/layout.html.erb', __FILE__), "app/views/layouts/#{layout}.html.erb"
41
+ erb_template File.expand_path('../templates/layout.html.erb', __FILE__), "app/views/layouts/#{layout}.html.erb"
35
42
 
36
43
  application = name ? ", application: '#{name}'" : ''
37
44
  route "joosy '/#{name}'#{application}"
@@ -1,30 +1,60 @@
1
- require 'joosy/generators'
2
- require 'ejs'
1
+ require 'active_support/all'
2
+ require 'sprockets'
3
+ require 'execjs'
3
4
 
4
5
  module Joosy
5
6
  module Generators
6
7
  class Base < ::Rails::Generators::Base
8
+ no_tasks do
9
+ class <<self
10
+ attr_accessor :kind
11
+ end
12
+
13
+ alias_method :erb_template, :template
14
+
15
+ def template(source, destination=nil, config={})
16
+ destination ||= source
17
+ source = File.expand_path(find_in_source_paths(source.to_s))
18
+ context = instance_eval('binding')
19
+
20
+ create_file destination, nil, config do
21
+ self.class.ejs ::File.read(source), @options
22
+ end
23
+ end
24
+ end
25
+
7
26
  protected
8
27
 
28
+ def self.sprockets
29
+ return @sprockets if @sprockets
30
+
31
+ @sprockets = Sprockets::Environment.new
32
+ @sprockets.append_path File.expand_path('../../../../../vendor/', __FILE__)
33
+ @sprockets
34
+ end
35
+
36
+ def self.ejs(template, data)
37
+ ExecJS.compile(sprockets['ejs'].to_s).eval("ejs.compile(#{template.to_json})(#{data.to_json})")
38
+ end
39
+
9
40
  def self.source_root
10
41
  Joosy.templates_path
11
42
  end
43
+ end
12
44
 
13
- def run(instructions)
14
- instructions.each do |i|
15
- case i[0]
16
- when 'file'
17
- create_file i[1]
18
- when 'copy'
19
- copy_file i[2], i[1]
20
- when 'template'
21
- source = File.expand_path(find_in_source_paths(i[2]))
22
-
23
- create_file i[1] do
24
- EJS.evaluate(File.read(source), i[3])
25
- end
26
- end
27
- end
45
+ class Entity < Base
46
+ argument :name, type: :string
47
+ argument :application, type: :string, optional: true
48
+
49
+ def create_files
50
+ @options = {
51
+ 'name' => name,
52
+ 'namespace' => name.split('/')[0..-2].map(&:camelize).join('/'),
53
+ 'view' => name.split('/').last.underscore,
54
+ 'klass' => name.split('/').last.camelize
55
+ }
56
+
57
+ directory self.class.kind, Pathname.new('app/assets/javascripts/').join(application || '')
28
58
  end
29
59
  end
30
60
  end
@@ -1,11 +1,11 @@
1
- require_relative './base'
2
-
3
1
  module Joosy
4
2
  module Generators
5
- class ControllerGenerator < Base
3
+ class ControllerGenerator < ::Rails::Generators::Base
6
4
  argument :name, type: :string
7
5
  class_option :copy, :default => false, :type => :boolean, :desc => 'Indicates whether internal controller should be copied'
8
6
 
7
+ source_root ::Rails.root
8
+
9
9
  def create_files
10
10
  if options["copy"]
11
11
  template File.expand_path('../../../../joosy/rails/controller.rb', __FILE__), "app/controller/joosy/rails/serve_controller.rb"
@@ -2,14 +2,8 @@ require_relative './base'
2
2
 
3
3
  module Joosy
4
4
  module Generators
5
- class LayoutGenerator < Base
6
- argument :name, type: :string
7
- argument :application, type: :string, optional: true
8
-
9
- def create_files
10
- self.destination_root = ::Rails.root.join('app/assets/javascripts/').join(application || '')
11
- run Joosy::Generators.pregenerate('layout', {name: name})
12
- end
5
+ class LayoutGenerator < Entity
6
+ self.kind = 'layout'
13
7
  end
14
8
  end
15
9
  end
@@ -2,14 +2,8 @@ require_relative './base'
2
2
 
3
3
  module Joosy
4
4
  module Generators
5
- class PageGenerator < Base
6
- argument :name, type: :string
7
- argument :application, type: :string, optional: true
8
-
9
- def create_files
10
- self.destination_root = ::Rails.root.join('app/assets/javascripts/').join(application || '')
11
- run Joosy::Generators.pregenerate('page', {name: name})
12
- end
5
+ class PageGenerator < Entity
6
+ self.kind = 'page'
13
7
  end
14
8
  end
15
- end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative './base'
2
+
3
+ module Joosy
4
+ module Generators
5
+ class ResourceGenerator < Entity
6
+ self.kind = 'resource'
7
+ end
8
+ end
9
+ end
@@ -2,14 +2,8 @@ require_relative './base'
2
2
 
3
3
  module Joosy
4
4
  module Generators
5
- class WidgetGenerator < Base
6
- argument :name, type: :string
7
- argument :application, type: :string, optional: true
8
-
9
- def create_files
10
- self.destination_root = ::Rails.root.join('app/assets/javascripts/').join(application || '')
11
- run Joosy::Generators.pregenerate('widget', {name: name})
12
- end
5
+ class WidgetGenerator < Entity
6
+ self.kind = 'widget'
13
7
  end
14
8
  end
15
- end
9
+ end
data/vendor/ejs.js ADDED
@@ -0,0 +1,581 @@
1
+ ejs = (function(){
2
+
3
+ // CommonJS require()
4
+
5
+ function require(p){
6
+ if ('fs' == p) return {};
7
+ var path = require.resolve(p)
8
+ , mod = require.modules[path];
9
+ if (!mod) throw new Error('failed to require "' + p + '"');
10
+ if (!mod.exports) {
11
+ mod.exports = {};
12
+ mod.call(mod.exports, mod, mod.exports, require.relative(path));
13
+ }
14
+ return mod.exports;
15
+ }
16
+
17
+ require.modules = {};
18
+
19
+ require.resolve = function (path){
20
+ var orig = path
21
+ , reg = path + '.js'
22
+ , index = path + '/index.js';
23
+ return require.modules[reg] && reg
24
+ || require.modules[index] && index
25
+ || orig;
26
+ };
27
+
28
+ require.register = function (path, fn){
29
+ require.modules[path] = fn;
30
+ };
31
+
32
+ require.relative = function (parent) {
33
+ return function(p){
34
+ if ('.' != p.substr(0, 1)) return require(p);
35
+
36
+ var path = parent.split('/')
37
+ , segs = p.split('/');
38
+ path.pop();
39
+
40
+ for (var i = 0; i < segs.length; i++) {
41
+ var seg = segs[i];
42
+ if ('..' == seg) path.pop();
43
+ else if ('.' != seg) path.push(seg);
44
+ }
45
+
46
+ return require(path.join('/'));
47
+ };
48
+ };
49
+
50
+
51
+ require.register("ejs.js", function(module, exports, require){
52
+
53
+ /*!
54
+ * EJS
55
+ * Copyright(c) 2012 TJ Holowaychuk <tj@vision-media.ca>
56
+ * MIT Licensed
57
+ */
58
+
59
+ /**
60
+ * Module dependencies.
61
+ */
62
+
63
+ var utils = require('./utils')
64
+ , fs = require('fs');
65
+
66
+ /**
67
+ * Library version.
68
+ */
69
+
70
+ exports.version = '0.7.2';
71
+
72
+ /**
73
+ * Filters.
74
+ *
75
+ * @type Object
76
+ */
77
+
78
+ var filters = exports.filters = require('./filters');
79
+
80
+ /**
81
+ * Intermediate js cache.
82
+ *
83
+ * @type Object
84
+ */
85
+
86
+ var cache = {};
87
+
88
+ /**
89
+ * Clear intermediate js cache.
90
+ *
91
+ * @api public
92
+ */
93
+
94
+ exports.clearCache = function(){
95
+ cache = {};
96
+ };
97
+
98
+ /**
99
+ * Translate filtered code into function calls.
100
+ *
101
+ * @param {String} js
102
+ * @return {String}
103
+ * @api private
104
+ */
105
+
106
+ function filtered(js) {
107
+ return js.substr(1).split('|').reduce(function(js, filter){
108
+ var parts = filter.split(':')
109
+ , name = parts.shift()
110
+ , args = parts.shift() || '';
111
+ if (args) args = ', ' + args;
112
+ return 'filters.' + name + '(' + js + args + ')';
113
+ });
114
+ };
115
+
116
+ /**
117
+ * Re-throw the given `err` in context to the
118
+ * `str` of ejs, `filename`, and `lineno`.
119
+ *
120
+ * @param {Error} err
121
+ * @param {String} str
122
+ * @param {String} filename
123
+ * @param {String} lineno
124
+ * @api private
125
+ */
126
+
127
+ function rethrow(err, str, filename, lineno){
128
+ var lines = str.split('\n')
129
+ , start = Math.max(lineno - 3, 0)
130
+ , end = Math.min(lines.length, lineno + 3);
131
+
132
+ // Error context
133
+ var context = lines.slice(start, end).map(function(line, i){
134
+ var curr = i + start + 1;
135
+ return (curr == lineno ? ' >> ' : ' ')
136
+ + curr
137
+ + '| '
138
+ + line;
139
+ }).join('\n');
140
+
141
+ // Alter exception message
142
+ err.path = filename;
143
+ err.message = (filename || 'ejs') + ':'
144
+ + lineno + '\n'
145
+ + context + '\n\n'
146
+ + err.message;
147
+
148
+ throw err;
149
+ }
150
+
151
+ /**
152
+ * Parse the given `str` of ejs, returning the function body.
153
+ *
154
+ * @param {String} str
155
+ * @return {String}
156
+ * @api public
157
+ */
158
+
159
+ var parse = exports.parse = function(str, options){
160
+ var options = options || {}
161
+ , open = options.open || exports.open || '<%'
162
+ , close = options.close || exports.close || '%>';
163
+
164
+ var buf = [
165
+ "var buf = [];"
166
+ , "\nwith (locals) {"
167
+ , "\n buf.push('"
168
+ ];
169
+
170
+ var lineno = 1;
171
+
172
+ var consumeEOL = false;
173
+ for (var i = 0, len = str.length; i < len; ++i) {
174
+ if (str.slice(i, open.length + i) == open) {
175
+ i += open.length
176
+
177
+ var prefix, postfix, line = '__stack.lineno=' + lineno;
178
+ switch (str.substr(i, 1)) {
179
+ case '=':
180
+ prefix = "', escape((" + line + ', ';
181
+ postfix = ")), '";
182
+ ++i;
183
+ break;
184
+ case '-':
185
+ prefix = "', (" + line + ', ';
186
+ postfix = "), '";
187
+ ++i;
188
+ break;
189
+ default:
190
+ prefix = "');" + line + ';';
191
+ postfix = "; buf.push('";
192
+ }
193
+
194
+ var end = str.indexOf(close, i)
195
+ , js = str.substring(i, end)
196
+ , start = i
197
+ , n = 0;
198
+
199
+ if ('-' == js[js.length-1]){
200
+ js = js.substring(0, js.length - 2);
201
+ consumeEOL = true;
202
+ }
203
+
204
+ while (~(n = js.indexOf("\n", n))) n++, lineno++;
205
+ if (js.substr(0, 1) == ':') js = filtered(js);
206
+ buf.push(prefix, js, postfix);
207
+ i += end - start + close.length - 1;
208
+
209
+ } else if (str.substr(i, 1) == "\\") {
210
+ buf.push("\\\\");
211
+ } else if (str.substr(i, 1) == "'") {
212
+ buf.push("\\'");
213
+ } else if (str.substr(i, 1) == "\r") {
214
+ buf.push(" ");
215
+ } else if (str.substr(i, 1) == "\n") {
216
+ if (consumeEOL) {
217
+ consumeEOL = false;
218
+ } else {
219
+ buf.push("\\n");
220
+ lineno++;
221
+ }
222
+ } else {
223
+ buf.push(str.substr(i, 1));
224
+ }
225
+ }
226
+
227
+ buf.push("');\n}\nreturn buf.join('');");
228
+ return buf.join('');
229
+ };
230
+
231
+ /**
232
+ * Compile the given `str` of ejs into a `Function`.
233
+ *
234
+ * @param {String} str
235
+ * @param {Object} options
236
+ * @return {Function}
237
+ * @api public
238
+ */
239
+
240
+ var compile = exports.compile = function(str, options){
241
+ options = options || {};
242
+
243
+ var input = JSON.stringify(str)
244
+ , filename = options.filename
245
+ ? JSON.stringify(options.filename)
246
+ : 'undefined';
247
+
248
+ // Adds the fancy stack trace meta info
249
+ str = [
250
+ 'var __stack = { lineno: 1, input: ' + input + ', filename: ' + filename + ' };',
251
+ rethrow.toString(),
252
+ 'try {',
253
+ exports.parse(str, options),
254
+ '} catch (err) {',
255
+ ' rethrow(err, __stack.input, __stack.filename, __stack.lineno);',
256
+ '}'
257
+ ].join("\n");
258
+
259
+ if (options.debug) console.log(str);
260
+ var fn = new Function('locals, filters, escape', str);
261
+ return function(locals){
262
+ return fn.call(this, locals, filters, utils.escape);
263
+ }
264
+ };
265
+
266
+ /**
267
+ * Render the given `str` of ejs.
268
+ *
269
+ * Options:
270
+ *
271
+ * - `locals` Local variables object
272
+ * - `cache` Compiled functions are cached, requires `filename`
273
+ * - `filename` Used by `cache` to key caches
274
+ * - `scope` Function execution context
275
+ * - `debug` Output generated function body
276
+ * - `open` Open tag, defaulting to "<%"
277
+ * - `close` Closing tag, defaulting to "%>"
278
+ *
279
+ * @param {String} str
280
+ * @param {Object} options
281
+ * @return {String}
282
+ * @api public
283
+ */
284
+
285
+ exports.render = function(str, options){
286
+ var fn
287
+ , options = options || {};
288
+
289
+ if (options.cache) {
290
+ if (options.filename) {
291
+ fn = cache[options.filename] || (cache[options.filename] = compile(str, options));
292
+ } else {
293
+ throw new Error('"cache" option requires "filename".');
294
+ }
295
+ } else {
296
+ fn = compile(str, options);
297
+ }
298
+
299
+ options.__proto__ = options.locals;
300
+ return fn.call(options.scope, options);
301
+ };
302
+
303
+ /**
304
+ * Render an EJS file at the given `path` and callback `fn(err, str)`.
305
+ *
306
+ * @param {String} path
307
+ * @param {Object|Function} options or callback
308
+ * @param {Function} fn
309
+ * @api public
310
+ */
311
+
312
+ exports.renderFile = function(path, options, fn){
313
+ var key = path + ':string';
314
+
315
+ if ('function' == typeof options) {
316
+ fn = options, options = {};
317
+ }
318
+
319
+ options.filename = path;
320
+
321
+ try {
322
+ var str = options.cache
323
+ ? cache[key] || (cache[key] = fs.readFileSync(path, 'utf8'))
324
+ : fs.readFileSync(path, 'utf8');
325
+
326
+ fn(null, exports.render(str, options));
327
+ } catch (err) {
328
+ fn(err);
329
+ }
330
+ };
331
+
332
+ // express support
333
+
334
+ exports.__express = exports.renderFile;
335
+
336
+ /**
337
+ * Expose to require().
338
+ */
339
+
340
+ if (require.extensions) {
341
+ require.extensions['.ejs'] = function(module, filename) {
342
+ source = require('fs').readFileSync(filename, 'utf-8');
343
+ module._compile(compile(source, {}), filename);
344
+ };
345
+ } else if (require.registerExtension) {
346
+ require.registerExtension('.ejs', function(src) {
347
+ return compile(src, {});
348
+ });
349
+ }
350
+
351
+ }); // module: ejs.js
352
+
353
+ require.register("filters.js", function(module, exports, require){
354
+
355
+ /*!
356
+ * EJS - Filters
357
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
358
+ * MIT Licensed
359
+ */
360
+
361
+ /**
362
+ * First element of the target `obj`.
363
+ */
364
+
365
+ exports.first = function(obj) {
366
+ return obj[0];
367
+ };
368
+
369
+ /**
370
+ * Last element of the target `obj`.
371
+ */
372
+
373
+ exports.last = function(obj) {
374
+ return obj[obj.length - 1];
375
+ };
376
+
377
+ /**
378
+ * Capitalize the first letter of the target `str`.
379
+ */
380
+
381
+ exports.capitalize = function(str){
382
+ str = String(str);
383
+ return str[0].toUpperCase() + str.substr(1, str.length);
384
+ };
385
+
386
+ /**
387
+ * Downcase the target `str`.
388
+ */
389
+
390
+ exports.downcase = function(str){
391
+ return String(str).toLowerCase();
392
+ };
393
+
394
+ /**
395
+ * Uppercase the target `str`.
396
+ */
397
+
398
+ exports.upcase = function(str){
399
+ return String(str).toUpperCase();
400
+ };
401
+
402
+ /**
403
+ * Sort the target `obj`.
404
+ */
405
+
406
+ exports.sort = function(obj){
407
+ return Object.create(obj).sort();
408
+ };
409
+
410
+ /**
411
+ * Sort the target `obj` by the given `prop` ascending.
412
+ */
413
+
414
+ exports.sort_by = function(obj, prop){
415
+ return Object.create(obj).sort(function(a, b){
416
+ a = a[prop], b = b[prop];
417
+ if (a > b) return 1;
418
+ if (a < b) return -1;
419
+ return 0;
420
+ });
421
+ };
422
+
423
+ /**
424
+ * Size or length of the target `obj`.
425
+ */
426
+
427
+ exports.size = exports.length = function(obj) {
428
+ return obj.length;
429
+ };
430
+
431
+ /**
432
+ * Add `a` and `b`.
433
+ */
434
+
435
+ exports.plus = function(a, b){
436
+ return Number(a) + Number(b);
437
+ };
438
+
439
+ /**
440
+ * Subtract `b` from `a`.
441
+ */
442
+
443
+ exports.minus = function(a, b){
444
+ return Number(a) - Number(b);
445
+ };
446
+
447
+ /**
448
+ * Multiply `a` by `b`.
449
+ */
450
+
451
+ exports.times = function(a, b){
452
+ return Number(a) * Number(b);
453
+ };
454
+
455
+ /**
456
+ * Divide `a` by `b`.
457
+ */
458
+
459
+ exports.divided_by = function(a, b){
460
+ return Number(a) / Number(b);
461
+ };
462
+
463
+ /**
464
+ * Join `obj` with the given `str`.
465
+ */
466
+
467
+ exports.join = function(obj, str){
468
+ return obj.join(str || ', ');
469
+ };
470
+
471
+ /**
472
+ * Truncate `str` to `len`.
473
+ */
474
+
475
+ exports.truncate = function(str, len){
476
+ str = String(str);
477
+ return str.substr(0, len);
478
+ };
479
+
480
+ /**
481
+ * Truncate `str` to `n` words.
482
+ */
483
+
484
+ exports.truncate_words = function(str, n){
485
+ var str = String(str)
486
+ , words = str.split(/ +/);
487
+ return words.slice(0, n).join(' ');
488
+ };
489
+
490
+ /**
491
+ * Replace `pattern` with `substitution` in `str`.
492
+ */
493
+
494
+ exports.replace = function(str, pattern, substitution){
495
+ return String(str).replace(pattern, substitution || '');
496
+ };
497
+
498
+ /**
499
+ * Prepend `val` to `obj`.
500
+ */
501
+
502
+ exports.prepend = function(obj, val){
503
+ return Array.isArray(obj)
504
+ ? [val].concat(obj)
505
+ : val + obj;
506
+ };
507
+
508
+ /**
509
+ * Append `val` to `obj`.
510
+ */
511
+
512
+ exports.append = function(obj, val){
513
+ return Array.isArray(obj)
514
+ ? obj.concat(val)
515
+ : obj + val;
516
+ };
517
+
518
+ /**
519
+ * Map the given `prop`.
520
+ */
521
+
522
+ exports.map = function(arr, prop){
523
+ return arr.map(function(obj){
524
+ return obj[prop];
525
+ });
526
+ };
527
+
528
+ /**
529
+ * Reverse the given `obj`.
530
+ */
531
+
532
+ exports.reverse = function(obj){
533
+ return Array.isArray(obj)
534
+ ? obj.reverse()
535
+ : String(obj).split('').reverse().join('');
536
+ };
537
+
538
+ /**
539
+ * Get `prop` of the given `obj`.
540
+ */
541
+
542
+ exports.get = function(obj, prop){
543
+ return obj[prop];
544
+ };
545
+
546
+ /**
547
+ * Packs the given `obj` into json string
548
+ */
549
+ exports.json = function(obj){
550
+ return JSON.stringify(obj);
551
+ };
552
+ }); // module: filters.js
553
+
554
+ require.register("utils.js", function(module, exports, require){
555
+
556
+ /*!
557
+ * EJS
558
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
559
+ * MIT Licensed
560
+ */
561
+
562
+ /**
563
+ * Escape the given string of `html`.
564
+ *
565
+ * @param {String} html
566
+ * @return {String}
567
+ * @api private
568
+ */
569
+
570
+ exports.escape = function(html){
571
+ return String(html)
572
+ .replace(/&(?!\w+;)/g, '&amp;')
573
+ .replace(/</g, '&lt;')
574
+ .replace(/>/g, '&gt;')
575
+ .replace(/"/g, '&quot;');
576
+ };
577
+
578
+ }); // module: utils.js
579
+
580
+ return require("ejs");
581
+ })();
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joosy-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta.3
4
+ version: 1.0.0.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Staal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-30 00:00:00.000000000 Z
11
+ date: 2014-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: joosy
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.2.0.alpha.48
19
+ version: 1.2.0.beta.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: 1.2.0.alpha.48
26
+ version: 1.2.0.beta.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sprockets
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +53,21 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: ejs
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - '>='
@@ -106,20 +120,24 @@ files:
106
120
  - LICENSE.txt
107
121
  - README.md
108
122
  - Rakefile
123
+ - app/assets/javascripts/joosy/railties.coffee.erb
124
+ - app/assets/javascripts/joosy/resource_loader.coffee
109
125
  - joosy-rails.gemspec
110
- - lib/joosy/generators.rb
111
126
  - lib/joosy/rails.rb
112
127
  - lib/joosy/rails/controller.rb
113
128
  - lib/joosy/rails/engine.rb
129
+ - lib/joosy/rails/routing.rb
114
130
  - lib/joosy/rails/version.rb
115
131
  - lib/rails/generators/joosy/application_generator.rb
116
132
  - lib/rails/generators/joosy/base.rb
117
133
  - lib/rails/generators/joosy/controller_generator.rb
118
134
  - lib/rails/generators/joosy/layout_generator.rb
119
135
  - lib/rails/generators/joosy/page_generator.rb
136
+ - lib/rails/generators/joosy/resource_generator.rb
120
137
  - lib/rails/generators/joosy/templates/controller.rb
121
138
  - lib/rails/generators/joosy/templates/layout.html.erb
122
139
  - lib/rails/generators/joosy/widget_generator.rb
140
+ - vendor/ejs.js
123
141
  homepage: http://github.com/joosy/rails
124
142
  licenses:
125
143
  - MIT
@@ -140,8 +158,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
158
  version: 1.3.1
141
159
  requirements: []
142
160
  rubyforge_project:
143
- rubygems_version: 2.0.6
161
+ rubygems_version: 2.0.3
144
162
  signing_key:
145
163
  specification_version: 4
146
164
  summary: Joosy Rails ties
147
165
  test_files: []
166
+ has_rdoc:
@@ -1,20 +0,0 @@
1
- require 'sprockets'
2
- require 'execjs'
3
- require 'ejs'
4
-
5
- module Joosy
6
- module Generators
7
- def self.pregenerate(generator, arguments)
8
- environment = Sprockets::Environment.new
9
- environment.append_path Joosy.generators_path
10
-
11
- source = environment['base.js'].to_s
12
- source << environment["#{generator}.js"].to_s
13
- source << <<-JS
14
- Generator.prototype.version = function(){return '#{Joosy::VERSION}'};
15
- JS
16
-
17
- ExecJS.compile(source).eval("new Generator(#{arguments.to_json}).generate()")
18
- end
19
- end
20
- end