pinkman 0.9.9.8 → 0.9.9.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +12 -12
- data/app/assets/javascripts/pinkman_base/collection.coffee +48 -20
- data/app/assets/javascripts/pinkman_base/common.coffee +38 -9
- data/app/assets/javascripts/pinkman_base/controller.coffee +134 -36
- data/app/assets/javascripts/pinkman_base/mixins.coffee +8 -4
- data/app/assets/javascripts/pinkman_base/object.coffee.erb +15 -13
- data/app/assets/javascripts/pinkman_base/pinkman.coffee +16 -0
- data/app/assets/javascripts/pinkman_base/render.coffee.erb +17 -5
- data/app/assets/javascripts/pinkman_base/router.coffee +95 -46
- data/app/assets/javascripts/pinkman_base/tools.coffee +3 -3
- data/app/assets/stylesheets/_colors.scss +45 -0
- data/app/assets/stylesheets/_custom_colors.scss +7 -0
- data/app/assets/stylesheets/_mixins.scss +39 -0
- data/app/assets/stylesheets/_settings.scss +1 -0
- data/app/assets/stylesheets/pinkman/buttons.scss +15 -0
- data/app/assets/stylesheets/pinkman/colors.scss +99 -0
- data/app/assets/stylesheets/pinkman/containers.scss +15 -0
- data/app/assets/stylesheets/pinkman/elements.scss +33 -0
- data/app/assets/stylesheets/pinkman/forms.scss +89 -0
- data/app/assets/stylesheets/pinkman/grid.scss +120 -0
- data/app/assets/stylesheets/pinkman/imgs.scss +7 -0
- data/app/assets/stylesheets/pinkman/lists.scss +58 -0
- data/app/assets/stylesheets/pinkman/loaders.scss +495 -0
- data/app/assets/stylesheets/pinkman/margins.scss +65 -0
- data/app/assets/stylesheets/pinkman/portfolio.scss +59 -0
- data/app/assets/stylesheets/pinkman/pygments.css.erb +1 -0
- data/app/assets/stylesheets/pinkman/reset.scss +51 -0
- data/app/assets/stylesheets/pinkman/sector.scss +10 -0
- data/app/assets/stylesheets/pinkman/tables.scss +62 -0
- data/app/assets/stylesheets/pinkman/typo.scss +104 -0
- data/app/assets/stylesheets/pinkman.css +17 -0
- data/app/controllers/pinkman/pinkman_controller.rb +6 -0
- data/app/helpers/pinkman/pinkman_helper.rb +14 -0
- data/app/views/pinkman/_error_for.html.slim +4 -0
- data/app/views/pinkman/pinkman/_form_input.html.slim +4 -0
- data/app/views/pinkman/pinkman/_form_select.html.slim +13 -0
- data/app/views/pinkman/pinkman/_form_textarea.html.slim +4 -0
- data/app/views/pinkman/pinkman/hello.html.erb +53 -0
- data/config/routes.rb +7 -0
- data/lib/generators/pinkman/USAGE +60 -14
- data/lib/generators/pinkman/app_base_generator.rb +16 -4
- data/lib/generators/pinkman/controller_generator.rb +29 -0
- data/lib/generators/pinkman/crud_generator.rb +24 -0
- data/lib/generators/pinkman/initializer_generator.rb +12 -0
- data/lib/generators/pinkman/install_generator.rb +29 -2
- data/lib/generators/pinkman/model_generator.rb +2 -2
- data/lib/generators/pinkman/page_generator.rb +15 -0
- data/lib/generators/pinkman/route_generator.rb +40 -0
- data/lib/generators/pinkman/route_resource_generator.rb +40 -0
- data/lib/generators/pinkman/template_generator.rb +47 -0
- data/lib/generators/pinkman/templates/api.rb.erb +6 -6
- data/lib/generators/pinkman/templates/api_controller.rb +22 -18
- data/lib/generators/pinkman/templates/app.coffee.erb +1 -0
- data/lib/generators/pinkman/templates/app_app.coffee.erb +1 -0
- data/lib/generators/pinkman/templates/app_collection.coffee.erb +1 -1
- data/lib/generators/pinkman/templates/app_object.coffee.erb +1 -1
- data/lib/generators/pinkman/templates/app_router.coffee.erb +1 -0
- data/lib/generators/pinkman/templates/app_routes.coffee.erb +34 -0
- data/lib/generators/pinkman/templates/controller.coffee.erb +4 -0
- data/lib/generators/pinkman/templates/example.mixin.coffee.erb +32 -0
- data/lib/generators/pinkman/templates/hello.controller.coffee.erb +98 -0
- data/lib/generators/pinkman/templates/initializer.rb.erb +6 -0
- data/lib/generators/pinkman/templates/my.pinkman.app.js +70 -0
- data/lib/generators/pinkman/templates/pink_template.html.erb.erb +4 -0
- data/lib/generators/pinkman/templates/pink_template.html.haml.erb +3 -0
- data/lib/generators/pinkman/templates/pink_template.html.slim.erb +3 -0
- data/lib/generators/pinkman/templates/serializer.rb.erb +6 -6
- data/lib/pinkman/base_helper.rb +15 -0
- data/lib/pinkman/form_helper/form_helpers.rb +65 -0
- data/lib/pinkman/form_helper.rb +36 -0
- data/lib/pinkman/serializer/base.rb +0 -1
- data/lib/pinkman/version.rb +1 -1
- data/lib/pinkman/views_helpers/collection_helper.rb +16 -0
- data/lib/pinkman/views_helpers/conditional_helper.rb +19 -0
- data/lib/pinkman/views_helpers/dispatcher.rb +27 -0
- data/lib/pinkman/views_helpers/form_helper.rb +63 -0
- data/lib/pinkman/views_helpers/template_helper.rb +65 -0
- data/lib/pinkman/views_helpers/writer_helper.rb +31 -0
- data/lib/pinkman/views_helpers.rb +71 -0
- data/lib/pinkman.rb +31 -5
- data/public/jquery.pinkman.min.js +4 -0
- data/public/pinkman.min.js +2 -29
- metadata +61 -4
- data/app/helpers/pinkman_helper.rb +0 -87
@@ -7,16 +7,31 @@ module Pinkman
|
|
7
7
|
|
8
8
|
def create_directories
|
9
9
|
FileUtils.mkdir_p Rails.root.join('app','views','pinkman')
|
10
|
-
FileUtils.mkdir_p Rails.root.join('app','assets','javascripts','pinkman','models')
|
10
|
+
FileUtils.mkdir_p Rails.root.join('app','assets','javascripts','pinkman','app','models')
|
11
|
+
FileUtils.mkdir_p Rails.root.join('app','assets','javascripts','pinkman','app','controllers')
|
12
|
+
FileUtils.mkdir_p Rails.root.join('app','assets','javascripts','pinkman','app','mixins')
|
13
|
+
FileUtils.mkdir_p Rails.root.join('app','assets','javascripts','pinkman','base')
|
14
|
+
FileUtils.mkdir_p Rails.root.join('app','assets','javascripts','pinkman','config')
|
15
|
+
FileUtils.mkdir_p Rails.root.join('app','assets','javascripts','pinkman','test')
|
11
16
|
FileUtils.mkdir_p Rails.root.join('app','serializers')
|
12
17
|
FileUtils.mkdir_p Rails.root.join('app','controllers','api')
|
13
18
|
end
|
14
19
|
|
15
20
|
def create_api_routes
|
16
21
|
inject_into_file 'config/routes.rb', after: ".routes.draw do" do
|
17
|
-
["\n \n \t" 'namespace :api do',"\tend"].join("\n")
|
22
|
+
["\n \n \t" + 'namespace :api do',"\tend"].join("\n")
|
18
23
|
end
|
19
24
|
end
|
25
|
+
|
26
|
+
def modify_application_js
|
27
|
+
append_to_file Rails.root.join('app','assets','javascripts','application.js') do
|
28
|
+
"\n//= require my.pinkman.app"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def copy_my_pinkman_app_js_to_rails
|
33
|
+
copy_file "my.pinkman.app.js", Rails.root.join('app','assets','javascripts','my.pinkman.app.js')
|
34
|
+
end
|
20
35
|
|
21
36
|
def create_api_controller_file
|
22
37
|
copy_file "api_controller.rb", Rails.root.join('app','controllers','api_controller.rb')
|
@@ -26,5 +41,17 @@ module Pinkman
|
|
26
41
|
generate 'pinkman:app_base'
|
27
42
|
end
|
28
43
|
|
44
|
+
def create_initializer
|
45
|
+
generate 'pinkman:initializer'
|
46
|
+
end
|
47
|
+
|
48
|
+
def install_hello_world_controller
|
49
|
+
copy_file "hello.controller.coffee.erb", Rails.root.join('app','assets','javascripts','pinkman','app','controllers','hello.coffee')
|
50
|
+
end
|
51
|
+
|
52
|
+
def install_mixin_example
|
53
|
+
copy_file "example.mixin.coffee.erb", Rails.root.join('app','assets','javascripts','pinkman','app','mixins','example.mixin.coffee')
|
54
|
+
end
|
55
|
+
|
29
56
|
end
|
30
57
|
end
|
@@ -7,8 +7,8 @@ module Pinkman
|
|
7
7
|
argument :class_name, type: :string, default: "nameHere"
|
8
8
|
|
9
9
|
def generate_files
|
10
|
-
template "object.coffee.erb", "app/assets/javascripts/pinkman/models/#{directory_name}/#{object_file_name}"
|
11
|
-
template "collection.coffee.erb", "app/assets/javascripts/pinkman/models/#{directory_name}/#{collection_file_name}"
|
10
|
+
template "object.coffee.erb", "app/assets/javascripts/pinkman/app/models/#{directory_name}/#{object_file_name}"
|
11
|
+
template "collection.coffee.erb", "app/assets/javascripts/pinkman/app/models/#{directory_name}/#{collection_file_name}"
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Pinkman
|
4
|
+
class PageGenerator < ::Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
argument :page_name, type: :string, default: "nameHere"
|
8
|
+
|
9
|
+
def exec
|
10
|
+
generate "pinkman:route #{page_name}"
|
11
|
+
generate "pinkman:controller #{page_name}"
|
12
|
+
generate "pinkman:template #{page_name}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Pinkman
|
4
|
+
class RouteGenerator < ::Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
argument :route_arg, type: :string
|
8
|
+
|
9
|
+
def normalize_argument
|
10
|
+
self.route_arg = route_arg.downcase.gsub(' ','_').strip.squeeze('_').gsub(/:/,'/')
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_route
|
14
|
+
# binding.pry
|
15
|
+
if File.file?(file_path)
|
16
|
+
inject_into_file file_path, after: ".define (routes) ->" do
|
17
|
+
%/
|
18
|
+
|
19
|
+
routes.match '#{route_path}', controller: '#{controller_name}'/
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def route_path
|
27
|
+
'/' + route_arg.sub('/index','')
|
28
|
+
end
|
29
|
+
|
30
|
+
def controller_name
|
31
|
+
route_arg.split('/').join('-')
|
32
|
+
end
|
33
|
+
|
34
|
+
def file_path
|
35
|
+
Rails.root.join('app','assets','javascripts','pinkman','config','routes.coffee')
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Pinkman
|
4
|
+
class RouteResourceGenerator < ::Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
argument :route_arg, type: :string
|
8
|
+
|
9
|
+
def normalize_argument
|
10
|
+
self.route_arg = route_arg.downcase.gsub(' ','_').strip.squeeze('_').gsub(/:/,'/')
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_route
|
14
|
+
# binding.pry
|
15
|
+
if File.file?(file_path)
|
16
|
+
inject_into_file file_path, after: ".define (routes) ->" do
|
17
|
+
%/
|
18
|
+
|
19
|
+
routes.resources '#{route_path}'/
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def route_path
|
27
|
+
'/' + route_arg.sub('/index','')
|
28
|
+
end
|
29
|
+
|
30
|
+
def controller_name
|
31
|
+
route_arg.split('/').join('-')
|
32
|
+
end
|
33
|
+
|
34
|
+
def file_path
|
35
|
+
Rails.root.join('app','assets','javascripts','pinkman','config','routes.coffee')
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Pinkman
|
4
|
+
class TemplateGenerator < ::Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
argument :pink_template_arg, type: :string
|
8
|
+
|
9
|
+
def normalize_argument
|
10
|
+
self.pink_template_arg = pink_template_arg.downcase.gsub(' ','_').strip.squeeze('_').gsub(/:/,'/')
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_pink_template
|
14
|
+
template template_path, file_path
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def template_engine_extension
|
20
|
+
begin Rails.configuration.generators.options[:rails][:template_engine].to_s rescue 'erb' end
|
21
|
+
end
|
22
|
+
|
23
|
+
def template_path
|
24
|
+
"pink_template.html.#{template_engine_extension}.erb"
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_path
|
28
|
+
path = (pink_template_arg + ".html.#{template_engine_extension}").split('/')
|
29
|
+
path[path.length-1] = '_' + path.last
|
30
|
+
Rails.root.join('app','views','pinkman',*path.map{|p| p})
|
31
|
+
end
|
32
|
+
|
33
|
+
def path
|
34
|
+
file_path.to_s.sub(Rails.root.to_s,'')
|
35
|
+
end
|
36
|
+
|
37
|
+
def controller_name
|
38
|
+
pink_template_arg.split('/').join('-').gsub(/[_\/]/,'-')
|
39
|
+
end
|
40
|
+
|
41
|
+
def pink_template_name
|
42
|
+
controller_name
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
@@ -6,19 +6,19 @@ class Api::<%= controller_name %> < ApiController
|
|
6
6
|
# get api/<%= api_name %>
|
7
7
|
def index
|
8
8
|
<%= collection_name %> = <%= active_record_model_name %>.limit(params[:limit]).offset(params[:offset])
|
9
|
-
render json: <%= collection_name %>.
|
9
|
+
render json: <%= collection_name %>.json(current_scope)
|
10
10
|
end
|
11
11
|
|
12
12
|
# get api/<%= api_name %>/:id
|
13
13
|
def show
|
14
|
-
render json: @<%= instance_name %>.
|
14
|
+
render json: @<%= instance_name %>.json(current_scope)
|
15
15
|
end
|
16
16
|
|
17
17
|
# get api/<%= api_name %>/search/:query
|
18
18
|
def search
|
19
19
|
if params[:query].present?
|
20
20
|
<%= collection_name %> = <%= active_record_model_name %>.search(params[:query]).limit(params[:limit]).offset(params[:offset])
|
21
|
-
render json: <%= collection_name %>.
|
21
|
+
render json: <%= collection_name %>.json(current_scope)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -26,19 +26,19 @@ class Api::<%= controller_name %> < ApiController
|
|
26
26
|
def create
|
27
27
|
@<%= instance_name %>.assign_attributes <%= params_method_name %>
|
28
28
|
@<%= instance_name %>.save
|
29
|
-
render json: @<%= instance_name %>.
|
29
|
+
render json: @<%= instance_name %>.json(current_scope)
|
30
30
|
end
|
31
31
|
|
32
32
|
# put/patch api/<%= api_name %>/:id
|
33
33
|
def update
|
34
34
|
@<%= instance_name %>.update <%= params_method_name %>
|
35
|
-
render json: @<%= instance_name %>.
|
35
|
+
render json: @<%= instance_name %>.json(current_scope)
|
36
36
|
end
|
37
37
|
|
38
38
|
# delete api/<%= api_name %>/:id
|
39
39
|
def destroy
|
40
40
|
@<%= instance_name %>.destroy
|
41
|
-
render json: @<%= instance_name %>.
|
41
|
+
render json: @<%= instance_name %>.json(current_scope)
|
42
42
|
end
|
43
43
|
|
44
44
|
protected
|
@@ -6,14 +6,25 @@ class ApiController < ApplicationController
|
|
6
6
|
params[:limit] = 20 if params[:limit].blank?
|
7
7
|
params[:offset] = 0 if params[:offset].blank?
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
# TO DO: rewrite the current_scope method the way you want.
|
11
|
+
def current_scope
|
12
|
+
:public
|
13
|
+
end
|
11
14
|
|
12
15
|
# You can define it according to the current user and his permissions
|
13
16
|
# or through params[:scope] or any other way you want.
|
14
17
|
# It's your choice.
|
15
18
|
|
16
|
-
#
|
19
|
+
# ***** IMPORTANT *************************************************************************
|
20
|
+
# * *
|
21
|
+
# * Never pass params[:scope] directly to serializers. *
|
22
|
+
# * params[:scope] must to be whitelisted if you are going to allow/use it. *
|
23
|
+
# * See examples bellow. *
|
24
|
+
# * *
|
25
|
+
#******************************************************************************************
|
26
|
+
|
27
|
+
# --- Examples
|
17
28
|
|
18
29
|
# Example 1:
|
19
30
|
# def current_scope
|
@@ -22,35 +33,28 @@ class ApiController < ApplicationController
|
|
22
33
|
|
23
34
|
# Example 2:
|
24
35
|
# def current_scope
|
25
|
-
# params[:scope]
|
36
|
+
# params[:scope].in?(['public','user_allowed','vip']) ? params[:scope].to_sym : :public
|
26
37
|
# end
|
27
38
|
|
28
39
|
# Example 3:
|
29
40
|
# def current_scope
|
30
|
-
#
|
41
|
+
# your_custom_scope_verification_method?(params[:scope]) ? params[:scope].to_sym : :public
|
31
42
|
# end
|
32
43
|
|
33
|
-
#
|
34
|
-
# * *
|
35
|
-
# * params[:scope] must to be whitelisted if you are going to allow/use it. *
|
36
|
-
# * *
|
37
|
-
# **************************************************************************************************
|
44
|
+
# --- Settings scope in client
|
38
45
|
|
39
|
-
# You can set params[:scope] value in the client (js/coffee).
|
46
|
+
# You can set params[:scope] value directly in the client (js/coffee).
|
47
|
+
# By default, every pinkman requests is made with the 'public' scope. See bellow how to change this behaviour.
|
40
48
|
|
41
49
|
# 1. In a single object/collection
|
42
|
-
# obj = new Pinkman.object; obj.set('scope','
|
50
|
+
# obj = new Pinkman.object; obj.set('scope','your_scope')
|
43
51
|
|
44
52
|
# 2. In all instances of a given model (object or collection)
|
45
53
|
# class YourModel extends Pinkman.object
|
46
|
-
# YourModel.scope = '
|
54
|
+
# YourModel.scope = 'your_scope'
|
47
55
|
|
48
56
|
# 3. In all instances through AppObject and AppCollection
|
49
|
-
# AppObject.scope = '
|
50
|
-
# AppCollection.scope = '
|
51
|
-
|
52
|
-
def current_scope
|
53
|
-
:public
|
54
|
-
end
|
57
|
+
# AppObject.scope = 'your_scope'
|
58
|
+
# AppCollection.scope = 'your_scope'
|
55
59
|
|
56
60
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
class window.App extends Pinkman
|
@@ -0,0 +1 @@
|
|
1
|
+
class window.App extends Pinkman
|
@@ -1 +1 @@
|
|
1
|
-
class window.<%= app_collection_name %> extends
|
1
|
+
class window.<%= app_collection_name %> extends App.collection
|
@@ -1 +1 @@
|
|
1
|
-
class window.<%= app_object_name %> extends
|
1
|
+
class window.<%= app_object_name %> extends App.object
|
@@ -0,0 +1 @@
|
|
1
|
+
class window.AppRouter extends App.router
|
@@ -0,0 +1,34 @@
|
|
1
|
+
AppRouter.config
|
2
|
+
|
3
|
+
# --- Valid Options
|
4
|
+
# yield: Inform a valid css selector where Pinkman should yield content.
|
5
|
+
# analytics: insert your id (UA-YOURNUMBER)
|
6
|
+
# transition: any function that runs a animation and accepts a callback function as param.
|
7
|
+
|
8
|
+
yield: 'body'
|
9
|
+
|
10
|
+
|
11
|
+
AppRouter.define (routes) ->
|
12
|
+
|
13
|
+
# AppRouter maps url paths to Pinkman controllers.
|
14
|
+
|
15
|
+
# routes.match "url"
|
16
|
+
# Associates "/url" path to "url" controller
|
17
|
+
|
18
|
+
# routes.match 'url', controller: 'abc'
|
19
|
+
# Associates "/url" path to "abc" controller
|
20
|
+
|
21
|
+
# Namespace:
|
22
|
+
# You can use namespace to group routes
|
23
|
+
#
|
24
|
+
# namespace 'anything', (routes) ->
|
25
|
+
#
|
26
|
+
# routes.root 'controller'
|
27
|
+
# Associates "/anything /url" path to "abc" controller
|
28
|
+
#
|
29
|
+
# routes.match 'page'
|
30
|
+
# Associates "/anything/page" path to "page" controller
|
31
|
+
|
32
|
+
|
33
|
+
# Start the router. Obrigatory, else AppRouter does nothing.
|
34
|
+
AppRouter.start()
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# --- Mixins
|
2
|
+
# Mixins act like Ruby modules.
|
3
|
+
# You can share its functions among any classes/models you wish.
|
4
|
+
|
5
|
+
# --- Usage
|
6
|
+
|
7
|
+
# 1. Define a mixin:
|
8
|
+
|
9
|
+
# App.mixin 'hello',
|
10
|
+
# sayHello: (name) ->
|
11
|
+
# "Hello, #{name}."
|
12
|
+
|
13
|
+
|
14
|
+
# 2. Use it
|
15
|
+
|
16
|
+
# class window.Foo
|
17
|
+
# App.mix this, 'hello'
|
18
|
+
|
19
|
+
# class window.Bar extends AppObject
|
20
|
+
# @mix 'hello'
|
21
|
+
|
22
|
+
# class window.Baz extends AppCollection
|
23
|
+
# @mix 'hello'
|
24
|
+
|
25
|
+
# f = new Foo
|
26
|
+
# f.sayHello('John Doe') => 'Hello, John Doe.'
|
27
|
+
|
28
|
+
# b = new Bar
|
29
|
+
# b.sayHello('John Doe') => 'Hello, John Doe.'
|
30
|
+
|
31
|
+
# baz = new Baz
|
32
|
+
# baz.sayHello('John Doe') => 'Hello, John Doe.'
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# Yo!
|
2
|
+
# This is a nice overview of Pinkman Controllers.
|
3
|
+
# If you have the time, read it. :)
|
4
|
+
# Cheers,
|
5
|
+
# Unfair (Agilso),
|
6
|
+
# Pinkman.js creator.
|
7
|
+
|
8
|
+
# ------ Global Controller
|
9
|
+
|
10
|
+
# Yo! This is a global controller :)
|
11
|
+
# It runs once the document is ready.
|
12
|
+
App.ready ->
|
13
|
+
console.log "Yo World from Pinkman.js!"
|
14
|
+
|
15
|
+
# You can use it as many times as you want.
|
16
|
+
App.ready ->
|
17
|
+
console.log "Let's party rock! ;)"
|
18
|
+
console.log 'Find me in:'
|
19
|
+
console.log 'assets/javascripts/pinkman/app/controllers/hello.coffee'
|
20
|
+
|
21
|
+
|
22
|
+
# ------ Pinkman Controllers
|
23
|
+
|
24
|
+
# A Pinkman Controller looks a lot like a Rails Controller/Action.
|
25
|
+
|
26
|
+
# You get data and other complicated stuff from the models
|
27
|
+
# so you can render them with a view after that.
|
28
|
+
|
29
|
+
# This is the 'pinkman-hello' controller
|
30
|
+
App.controller 'pinkman-hello', ->
|
31
|
+
|
32
|
+
# It will be in effect in every page that
|
33
|
+
# has a html element with the 'pinkman-hello' id.
|
34
|
+
|
35
|
+
# The main function gets called everytime the controller initiates.
|
36
|
+
@main = ->
|
37
|
+
|
38
|
+
console.log "I am the Pinkman Hello controller!"
|
39
|
+
|
40
|
+
# ... your code ...
|
41
|
+
|
42
|
+
# Here you could load things from db, etc.
|
43
|
+
|
44
|
+
# ... your code ...
|
45
|
+
|
46
|
+
# This is the render function
|
47
|
+
# You can use it like this
|
48
|
+
# @render
|
49
|
+
# template: 'template-id'
|
50
|
+
# target: 'element-target-id'
|
51
|
+
# object: anyJsObject
|
52
|
+
|
53
|
+
# Or like this
|
54
|
+
|
55
|
+
# @render 'pinkman-hello'
|
56
|
+
|
57
|
+
# This last form is equivalent to
|
58
|
+
# @render
|
59
|
+
# template: 'pinkman-hello-template'
|
60
|
+
# target: 'pinkman-hello'
|
61
|
+
|
62
|
+
# A PinkmanObject is just a like a javascript object. But it's packed with a few more functionalities.
|
63
|
+
|
64
|
+
obj = new AppObject(title: 'Yo!', hint: 'You saw me here')
|
65
|
+
|
66
|
+
# Every Pinkman Object and Collection has a own render function.
|
67
|
+
# And it works like @render function.
|
68
|
+
obj.render('pinkman-hello')
|
69
|
+
|
70
|
+
# Pinkman binds every attribute in the template with the 'obj' object.
|
71
|
+
# So if you change them later... the template gets updated automatically.
|
72
|
+
# As long as you use the 'set' function.
|
73
|
+
|
74
|
+
# After 5 seconds, update the title
|
75
|
+
$p.sleep 5, ->
|
76
|
+
obj.set('title','Up & Running')
|
77
|
+
|
78
|
+
# Don't be scared of $p. It's just an alias of the Pinkman global variable.
|
79
|
+
# It has a few helper functions in it. Like the sleep function.
|
80
|
+
|
81
|
+
# Just one more thing about rendering.
|
82
|
+
# If a lot of things in 'obj' change, you can call "obj.render()" without any arguments. This will get this object to render itself again.
|
83
|
+
# obj.render()
|
84
|
+
|
85
|
+
|
86
|
+
# ------ Pinkman Actions
|
87
|
+
|
88
|
+
# Pinkman Controller also have actions.
|
89
|
+
# Pinkman Actions are associated to JS events.
|
90
|
+
# An action has the power to create a event listener and respond to it later, when it gets triggered.
|
91
|
+
# And its magic is that it always remember who is the object associated with the action and the dom element that triggered it.
|
92
|
+
|
93
|
+
@action 'you-are-over-me', 'mouseenter', (guessWhoIAm,jQueryEl) ->
|
94
|
+
console.log "Who am I? I have a hint: #{guessWhoIAm.hint}"
|
95
|
+
jQueryEl.html('Get off')
|
96
|
+
|
97
|
+
@action 'you-are-over-me', 'mouseleave', (obj,j) ->
|
98
|
+
j.html('Come here')
|
@@ -0,0 +1,70 @@
|
|
1
|
+
// This file will load Pinkman and all of your Pinkman App files: models, controllers, routes, etc.
|
2
|
+
// You are free to customize it
|
3
|
+
// as long as you stick to the loading ordering rules described at the bottom.
|
4
|
+
|
5
|
+
// **** IMPORTANT: this file need to be required after jquery.
|
6
|
+
// Yes. Pinkman depends on jquery.
|
7
|
+
|
8
|
+
|
9
|
+
// ------ 1. Pinkman & Template Engine
|
10
|
+
//= require pinkman_with_hogan
|
11
|
+
|
12
|
+
// This will load Pinkman.js packed together with a js template engine. (Hogan default)
|
13
|
+
|
14
|
+
// **** IMPORTANT:
|
15
|
+
// You need to make sure that config/initializers/pinkman.rb
|
16
|
+
// matches this template engine.
|
17
|
+
// And if you change it, run a 'rake tmp:clear'
|
18
|
+
// and restart the server just to make sure.
|
19
|
+
|
20
|
+
// Valid Options:
|
21
|
+
// 1. "pinkman_with_hogan"
|
22
|
+
// 2. "pinkman_with_handlebars"
|
23
|
+
// 3. "pinkman_with_markup"
|
24
|
+
// 4. "pinkman" (No template engine. Just Pinkman. See bellow.)
|
25
|
+
|
26
|
+
// Use the fourth option if you already have one of handlebars, hogan or markup template engine loaded. And don't forget to setup config/initializers/pinkman properly.
|
27
|
+
|
28
|
+
|
29
|
+
// ------ 2. App (must be after pinkman and before the rest)
|
30
|
+
//= require pinkman/base/app
|
31
|
+
|
32
|
+
|
33
|
+
// ------ 3. Collections
|
34
|
+
//= require pinkman/base/collection
|
35
|
+
|
36
|
+
|
37
|
+
// ------ 4. Objects
|
38
|
+
//= require pinkman/base/object
|
39
|
+
|
40
|
+
|
41
|
+
// ------ 5. Router
|
42
|
+
//= require pinkman/base/router
|
43
|
+
|
44
|
+
|
45
|
+
// ------ 6. Mixins (must be before models)
|
46
|
+
//= require_tree ./pinkman/app/mixins/
|
47
|
+
|
48
|
+
|
49
|
+
// ------ 7. Models (must be before controllers)
|
50
|
+
//= require_tree ./pinkman/app/models/
|
51
|
+
|
52
|
+
|
53
|
+
// ------ 8. Controllers
|
54
|
+
//= require_tree ./pinkman/app/controllers/
|
55
|
+
|
56
|
+
|
57
|
+
// ------ 9. Routes (must be last)
|
58
|
+
//= require ./pinkman/config/routes
|
59
|
+
|
60
|
+
|
61
|
+
// ------ Loading Order Rules:
|
62
|
+
// Follow these rules and you'll be fine. :)
|
63
|
+
|
64
|
+
// 1. "pinkman" or "pinkman_with_xxx" - must be first.
|
65
|
+
// 2. "pinkman/base/app" - must be second.
|
66
|
+
// 3. "pinkman/base/{colecction,object,router}" - each must be placed in this portion.
|
67
|
+
// 4. "pinkman/app/mixins" - mixins can be required here as they need to be available to models.
|
68
|
+
// 5. "pinkman/app/models" - your app models can be required here.
|
69
|
+
// 6. "pinkman/app/controllers" - your app controllers must be after your models.
|
70
|
+
// 7. "pinkman/config/routes" - routes needs to be last.
|
@@ -1,15 +1,15 @@
|
|
1
1
|
class <%= serializer_name %> < Pinkman::Serializer::Base
|
2
|
-
|
2
|
+
|
3
3
|
scope :public do |can|
|
4
4
|
can.read_attributes :all
|
5
5
|
can.write_attributes false
|
6
6
|
can.access_actions :index, :show
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
scope :admin do |can|
|
10
|
+
can.read_attributes :all
|
11
|
+
can.write_attributes :all
|
12
|
+
can.access_actions :all
|
13
|
+
end
|
14
14
|
|
15
15
|
end
|