joosy-rails 1.0.0.RC3 → 1.0.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -65
- data/app/helpers/joosy/preloaders_helper.rb +26 -0
- data/joosy-rails.gemspec +3 -5
- data/lib/joosy/generators.rb +21 -0
- data/lib/joosy/rails/engine.rb +1 -13
- data/lib/joosy/rails/sprockets.rb +15 -0
- data/lib/joosy/rails/version.rb +1 -1
- data/lib/joosy/rails.rb +20 -5
- data/lib/rails/generators/joosy/application_generator.rb +22 -39
- metadata +11 -50
- data/app/assets/javascripts/joosy/railties.coffee.erb +0 -13
- data/app/assets/javascripts/joosy/resource_loader.coffee +0 -37
- data/lib/joosy/rails/controller.rb +0 -13
- data/lib/joosy/rails/routing.rb +0 -41
- data/lib/rails/generators/joosy/base.rb +0 -61
- data/lib/rails/generators/joosy/controller_generator.rb +0 -18
- data/lib/rails/generators/joosy/layout_generator.rb +0 -9
- data/lib/rails/generators/joosy/page_generator.rb +0 -9
- data/lib/rails/generators/joosy/resource_generator.rb +0 -9
- data/lib/rails/generators/joosy/templates/controller.rb +0 -2
- data/lib/rails/generators/joosy/templates/layout.html.erb +0 -19
- data/lib/rails/generators/joosy/widget_generator.rb +0 -9
- data/vendor/ejs.js +0 -581
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4c118e1c080d32f38f9771960ad21bcd6f37d87
|
4
|
+
data.tar.gz: 749289c198631be8237ad36432705a01264b20c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81c3f9fb848175736b1f4a3ff1768d4641a25aa093826faa446eb44aeae747f119f243b7fcee04adc13e6f7400911e20d5653b557131cb8f8724aca5aef2c21f
|
7
|
+
data.tar.gz: 9a04ec21874424f969dc329d700a2a91458f1c80a0f69af005a717faab183340a00de9f80c50e2758e10fa9569650152f2c67e323502205736d6e564dac79d93
|
data/README.md
CHANGED
@@ -1,21 +1,6 @@
|
|
1
|
-
# Joosy::Rails
|
1
|
+
# Joosy::Rails
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
[![Gem Version](https://badge.fury.io/rb/joosy-rails.png)](http://badge.fury.io/rb/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/).
|
11
|
-
|
12
|
-
## Capabilities
|
13
|
-
|
14
|
-
* Full assets integration
|
15
|
-
* Generators
|
16
|
-
* Built-in serving controller
|
17
|
-
* Routes helpers
|
18
|
-
* Automatic Joosy Resources generation
|
3
|
+
TODO: Write a gem description
|
19
4
|
|
20
5
|
## Installation
|
21
6
|
|
@@ -27,56 +12,18 @@ And then execute:
|
|
27
12
|
|
28
13
|
$ bundle
|
29
14
|
|
30
|
-
|
31
|
-
|
32
|
-
### Generators
|
33
|
-
|
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 — 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)
|
15
|
+
Or install it yourself as:
|
47
16
|
|
48
|
-
|
17
|
+
$ gem install joosy-rails
|
49
18
|
|
50
|
-
|
51
|
-
|
52
|
-
#### rails g joosy:widget NAME (APPLICATION)
|
53
|
-
|
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`.
|
63
|
-
|
64
|
-
### Serving controller and helpers
|
65
|
-
|
66
|
-
This gem provides `joosy` routing helper which can be used in the following way:
|
67
|
-
|
68
|
-
```ruby
|
69
|
-
joosy '/', application: 'dummy'
|
70
|
-
```
|
71
|
-
|
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)
|
19
|
+
## Usage
|
77
20
|
|
78
|
-
|
21
|
+
TODO: Write usage instructions here
|
79
22
|
|
80
|
-
|
23
|
+
## Contributing
|
81
24
|
|
82
|
-
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Joosy
|
2
|
+
module PreloadersHelper
|
3
|
+
def javascript_preload_tag(name)
|
4
|
+
code = javascript_include_tag name
|
5
|
+
resources = code.scan(/(?:href|src)=['"]([^'"]+)['"]/).flatten
|
6
|
+
|
7
|
+
resources.map do |resource|
|
8
|
+
uri = URI.parse resource
|
9
|
+
path = ::Rails.root.to_s + "/public" + uri.path
|
10
|
+
size = File.size(path) rescue 0
|
11
|
+
[resource, size]
|
12
|
+
end.to_json.html_safe
|
13
|
+
end
|
14
|
+
|
15
|
+
def require_joosy_preloader_for(app_asset, options={})
|
16
|
+
preloader_asset = "joosy/preloaders/#{options[:preloader] || 'caching'}"
|
17
|
+
force_preloader = options[:force] || false
|
18
|
+
|
19
|
+
if force_preloader
|
20
|
+
require_asset preloader_asset
|
21
|
+
else
|
22
|
+
require_asset Rails.env == 'development' ? app_asset : preloader_asset
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/joosy-rails.gemspec
CHANGED
@@ -18,12 +18,10 @@ 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.
|
21
|
+
spec.add_dependency 'joosy', '>= 1.2.0.alpha'
|
22
22
|
spec.add_dependency 'sprockets'
|
23
23
|
spec.add_dependency 'execjs'
|
24
|
-
spec.add_dependency '
|
25
|
-
spec.add_dependency 'thor'
|
24
|
+
spec.add_dependency 'ejs'
|
26
25
|
|
27
|
-
spec.
|
28
|
-
spec.add_dependency 'jquery-form-rails'
|
26
|
+
spec.add_development_dependency 'rake'
|
29
27
|
end
|
@@ -0,0 +1,21 @@
|
|
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
|
+
arguments = arguments.join("','")
|
18
|
+
ExecJS.compile(source).eval("new Generator('#{arguments}').generate()")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/joosy/rails/engine.rb
CHANGED
@@ -3,22 +3,10 @@ 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
|
-
|
9
6
|
initializer 'joosy.extend.sprockets' do |app|
|
10
7
|
Joosy.assets_paths.each{|p| app.assets.append_path p}
|
11
8
|
end
|
12
|
-
|
13
|
-
initializer 'joosy.routing' do |app|
|
14
|
-
app.routes.prepend do
|
15
|
-
Engine.resources = []
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def route_dependencies
|
20
|
-
::Rails.application.routes_reloader.paths
|
21
|
-
end
|
22
9
|
end
|
23
10
|
end
|
24
11
|
end
|
12
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Joosy
|
2
|
+
module Rails
|
3
|
+
module Sprockets
|
4
|
+
module Asset
|
5
|
+
def dependencies_with_sizes
|
6
|
+
dependencies = to_a.map do |dependency|
|
7
|
+
[dependency.logical_path, dependency.to_s.length]
|
8
|
+
end
|
9
|
+
|
10
|
+
Hash[*dependencies.flatten]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/joosy/rails/version.rb
CHANGED
data/lib/joosy/rails.rb
CHANGED
@@ -1,9 +1,24 @@
|
|
1
|
-
require 'sugar-rails'
|
2
|
-
require 'jquery-form-rails'
|
3
|
-
require 'haml_coffee_assets'
|
4
1
|
require 'joosy'
|
5
2
|
|
6
3
|
require 'joosy/rails/version'
|
7
|
-
require 'joosy/rails/
|
4
|
+
require 'joosy/rails/sprockets'
|
8
5
|
require 'joosy/rails/engine'
|
9
|
-
|
6
|
+
|
7
|
+
module Joosy
|
8
|
+
module Rails
|
9
|
+
def self.resources(namespaces=nil)
|
10
|
+
predefined = {}
|
11
|
+
filtered_resources = Joosy::Rails::Engine.resources
|
12
|
+
if namespaces
|
13
|
+
namespaces = Array.wrap namespaces
|
14
|
+
filtered_resources = filtered_resources.select{|key, _| namespaces.include? key }
|
15
|
+
end
|
16
|
+
filtered_resources.each do |namespace, resources|
|
17
|
+
next unless resources && resources.size > 0
|
18
|
+
joosy_namespace = namespace.to_s.camelize.split('::').join('.')
|
19
|
+
predefined[joosy_namespace] = resources
|
20
|
+
end
|
21
|
+
predefined
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,47 +1,30 @@
|
|
1
|
-
|
1
|
+
require 'joosy/generators'
|
2
2
|
|
3
3
|
module Joosy
|
4
4
|
module Generators
|
5
|
-
class ApplicationGenerator < Base
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
'
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
def create_bindings
|
28
|
-
self.destination_root = ::Rails.root
|
29
|
-
|
30
|
-
if !name
|
31
|
-
index = ::Rails.root.join('app/assets/javascripts/application.js')
|
32
|
-
|
33
|
-
if File.exists?(index)
|
34
|
-
copy_file index, 'app/assets/javascripts/application.js-old'
|
35
|
-
remove_file index
|
5
|
+
class ApplicationGenerator < ::Rails::Generators::Base
|
6
|
+
source_root Joosy.templates_path
|
7
|
+
|
8
|
+
argument :name, :type => :string
|
9
|
+
|
10
|
+
def create_files
|
11
|
+
self.destination_root = ::Rails.root.join('app/assets/javascripts/').join(name)
|
12
|
+
instructions = Joosy::Generators.pregenerate('project/base', [name])
|
13
|
+
|
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
|
36
26
|
end
|
37
27
|
end
|
38
|
-
|
39
|
-
layout = 'joosy'
|
40
|
-
layout << "/#{name}" if name
|
41
|
-
erb_template File.expand_path('../templates/layout.html.erb', __FILE__), "app/views/layouts/#{layout}.html.erb"
|
42
|
-
|
43
|
-
application = name ? ", application: '#{name}'" : ''
|
44
|
-
route "joosy '/#{name}'#{application}"
|
45
28
|
end
|
46
29
|
end
|
47
30
|
end
|
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.
|
4
|
+
version: 1.0.0.alpha.1
|
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-
|
11
|
+
date: 2013-06-23 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.
|
19
|
+
version: 1.2.0.alpha
|
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.
|
26
|
+
version: 1.2.0.alpha
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sprockets
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: ejs
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - '>='
|
@@ -67,41 +67,13 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
|
-
type: :
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - '>='
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: sugar-rails
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - '>='
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - '>='
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: jquery-form-rails
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - '>='
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :runtime
|
76
|
+
type: :development
|
105
77
|
prerelease: false
|
106
78
|
version_requirements: !ruby/object:Gem::Requirement
|
107
79
|
requirements:
|
@@ -120,24 +92,14 @@ files:
|
|
120
92
|
- LICENSE.txt
|
121
93
|
- README.md
|
122
94
|
- Rakefile
|
123
|
-
- app/
|
124
|
-
- app/assets/javascripts/joosy/resource_loader.coffee
|
95
|
+
- app/helpers/joosy/preloaders_helper.rb
|
125
96
|
- joosy-rails.gemspec
|
97
|
+
- lib/joosy/generators.rb
|
126
98
|
- lib/joosy/rails.rb
|
127
|
-
- lib/joosy/rails/controller.rb
|
128
99
|
- lib/joosy/rails/engine.rb
|
129
|
-
- lib/joosy/rails/
|
100
|
+
- lib/joosy/rails/sprockets.rb
|
130
101
|
- lib/joosy/rails/version.rb
|
131
102
|
- lib/rails/generators/joosy/application_generator.rb
|
132
|
-
- lib/rails/generators/joosy/base.rb
|
133
|
-
- lib/rails/generators/joosy/controller_generator.rb
|
134
|
-
- lib/rails/generators/joosy/layout_generator.rb
|
135
|
-
- lib/rails/generators/joosy/page_generator.rb
|
136
|
-
- lib/rails/generators/joosy/resource_generator.rb
|
137
|
-
- lib/rails/generators/joosy/templates/controller.rb
|
138
|
-
- lib/rails/generators/joosy/templates/layout.html.erb
|
139
|
-
- lib/rails/generators/joosy/widget_generator.rb
|
140
|
-
- vendor/ejs.js
|
141
103
|
homepage: http://github.com/joosy/rails
|
142
104
|
licenses:
|
143
105
|
- MIT
|
@@ -158,9 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
120
|
version: 1.3.1
|
159
121
|
requirements: []
|
160
122
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.0.
|
123
|
+
rubygems_version: 2.0.2
|
162
124
|
signing_key:
|
163
125
|
specification_version: 4
|
164
126
|
summary: Joosy Rails ties
|
165
127
|
test_files: []
|
166
|
-
has_rdoc:
|
@@ -1,37 +0,0 @@
|
|
1
|
-
#= require joosy/resources
|
2
|
-
|
3
|
-
Joosy.ResourceLoader =
|
4
|
-
defineResource: (name, path, parent) ->
|
5
|
-
class @[name] extends parent
|
6
|
-
@entity name.underscore()
|
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 = res[0].singularize()
|
15
|
-
else
|
16
|
-
# scope
|
17
|
-
res = res[0]
|
18
|
-
res.camelize()
|
19
|
-
).join('.')
|
20
|
-
|
21
|
-
loadResources: (routes) ->
|
22
|
-
for route in routes
|
23
|
-
levels = route.match /\/[^\/]+(\/:[^\/]+)?/g
|
24
|
-
continue unless Object.isArray(levels)
|
25
|
-
rootPath = levels.pop()
|
26
|
-
name = rootPath.replace(/^\//, '').singularize().camelize()
|
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
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module Joosy
|
2
|
-
module Rails
|
3
|
-
class ServeController < ActionController::Base
|
4
|
-
def index
|
5
|
-
@prefix = request.env['SCRIPT_NAME']
|
6
|
-
layout = 'joosy'
|
7
|
-
layout << "/#{params[:application]}" if params[:application]
|
8
|
-
|
9
|
-
render text: '', layout: layout
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/lib/joosy/rails/routing.rb
DELETED
@@ -1,41 +0,0 @@
|
|
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,61 +0,0 @@
|
|
1
|
-
require 'active_support/all'
|
2
|
-
require 'sprockets'
|
3
|
-
require 'execjs'
|
4
|
-
|
5
|
-
module Joosy
|
6
|
-
module Generators
|
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
|
-
|
26
|
-
protected
|
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
|
-
|
40
|
-
def self.source_root
|
41
|
-
Joosy.templates_path
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
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 || '')
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Joosy
|
2
|
-
module Generators
|
3
|
-
class ControllerGenerator < ::Rails::Generators::Base
|
4
|
-
argument :name, type: :string
|
5
|
-
class_option :copy, :default => false, :type => :boolean, :desc => 'Indicates whether internal controller should be copied'
|
6
|
-
|
7
|
-
source_root ::Rails.root
|
8
|
-
|
9
|
-
def create_files
|
10
|
-
if options["copy"]
|
11
|
-
template File.expand_path('../../../../joosy/rails/controller.rb', __FILE__), "app/controller/joosy/rails/serve_controller.rb"
|
12
|
-
else
|
13
|
-
template File.expand_path('../templates/controller.rb', __FILE__), "app/controllers/#{name.underscore}_controller.rb"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title></title>
|
5
|
-
<script type="text/javascript">
|
6
|
-
window.JoosyEnvironment = {
|
7
|
-
router: {
|
8
|
-
prefix: <%= '<%= raw @prefix.to_json %'+'>' %>
|
9
|
-
}
|
10
|
-
}
|
11
|
-
</script>
|
12
|
-
|
13
|
-
<%= "<%= stylesheet_link_tag 'application', :media => 'all' %"+'>' %>
|
14
|
-
<%= "<%= javascript_include_tag '#{name}#{'/' if name}application' %"+'>' %>
|
15
|
-
<%= '<%= csrf_meta_tags %'+'>' %>
|
16
|
-
</head>
|
17
|
-
<body>
|
18
|
-
</body>
|
19
|
-
</html>
|
data/vendor/ejs.js
DELETED
@@ -1,581 +0,0 @@
|
|
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, '&')
|
573
|
-
.replace(/</g, '<')
|
574
|
-
.replace(/>/g, '>')
|
575
|
-
.replace(/"/g, '"');
|
576
|
-
};
|
577
|
-
|
578
|
-
}); // module: utils.js
|
579
|
-
|
580
|
-
return require("ejs");
|
581
|
-
})();
|