tomify 0.0.2 → 0.0.3

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: 46894bfb42ab884b427ee09afe3d9d43eef11088
4
- data.tar.gz: e87e72561204cd28de113947a41f9e70d6a9c764
3
+ metadata.gz: 5a150d58dedb05af95126801e20124eb12a0d560
4
+ data.tar.gz: b52597cf7561633de5a271dd217ddea463787a40
5
5
  SHA512:
6
- metadata.gz: 0330efeb2753614c08bd2ce715856b1fbb0acf66467bddd35395ea90c7d59876326c6e617c3babeed355013085c289176539691821f1a2758ab48452146dfafc
7
- data.tar.gz: 5d97b97430a8a3dbbf6db245eb4c174bb0d28cfab3758c5ac9add946e795ce2a447a383073b63beac0170255e9f9b05323226763eb65a8ced9dfbc704d42fcd5
6
+ metadata.gz: b5163f01fddc2fd9cbb95ee29a1482d757feb9f24a83faa87dc0bb1f90b8d23aa85b53ae107d14ad06e81e939e68a9592fe763ac743cff180e821fe691e19ba9
7
+ data.tar.gz: b3b4bc88c6243f44348b1c5623394c9149da46f0ec2f734665d2df3eb161d88101bda6d95b616945fbd6f8b0f25b1f791640a049130213aa3e498d1ec3d80274
@@ -2,3 +2,11 @@
2
2
  object = {}
3
3
  object[key] = value
4
4
  object
5
+
6
+ @EncodeObject = (object) ->
7
+ last = Object.keys(object).last
8
+ path = ""
9
+ for key, value of object
10
+ path += "#{encodeURIComponent(key)}=#{encodeURIComponent(value)}"
11
+ path += "&" unless key == last
12
+ path
@@ -11,7 +11,7 @@ String::startsWith ?= (s) -> @slice(0, s.length) == s
11
11
  String::endsWith ?= (s) -> s != "" && @slice(-s.length) == s
12
12
 
13
13
  String::transform = (method) ->
14
- string = @replace(/(?!^)([A-Z])/g, "_$1").lowercase
14
+ string = @replace(/![\._-]([A-Z])/, "_$1").lowercase
15
15
  string = string.splitAndJoin "-", method
16
16
  string = string.splitAndJoin "_", method
17
17
  string = string.splitAndJoin ".", method
@@ -25,8 +25,7 @@ String::splitAndJoin = (separator, method) ->
25
25
 
26
26
  Object.defineProperties String.prototype, {
27
27
  camelize: { get: ->
28
- word = (word.capitalize for word in @break()).join()
29
- word.charAt(0).lowercase + word.slice(1)
28
+ @transform (word) -> word.charAt(0).toLowerCase() + word.slice(1)
30
29
  },
31
30
  capitalize: { get: ->
32
31
  @transform (word) -> word.charAt(0).toUpperCase() + word.slice(1)
@@ -4,6 +4,7 @@ class @Model extends Observer
4
4
  @namespace namespace, new @(namespace, options)
5
5
  constructor: (namespace, options = {}) ->
6
6
  @name = namespace.split(".").last ? throw "Model: Requires Name"
7
+ @param = options.param ? @name.underscore
7
8
  @prefix = namespace.split(".").first.lowercase
8
9
  @path = options.path ? @name.underscore.pluralize
9
10
  @path = "/api/#{@prefix}/#{@path}"
@@ -20,7 +21,7 @@ class @Model extends Observer
20
21
  context.trigger name, response
21
22
  requested: (action) -> @requests[action].length > 0
22
23
  request: (type, nest) ->
23
- name = @name.underscore
24
+ param = @param
24
25
  basePath = @path
25
26
  (path, params) ->
26
27
  [path, params] = [params, path] if path instanceof Object
@@ -28,7 +29,7 @@ class @Model extends Observer
28
29
  route += "/#{path}" if path
29
30
  if nest
30
31
  [params, nest] = [{}, params]
31
- params[name] = nest
32
+ params[param] = nest
32
33
  Request[type](route, params)
33
34
  setDefaultActions: ->
34
35
  @setAction "find", @request "get"
@@ -1,3 +1,9 @@
1
+ params = {}
2
+ query = window.location.search[1..]
3
+ for param in query.split("&")
4
+ [key, value] = param.split("=")
5
+ params[decodeURIComponent(key)] = decodeURIComponent(value)
6
+ Store.create "Params", params
1
7
  Store.create "Messages", []
2
8
  Store.create "Settings", []
3
9
  Store.create "User", {}
@@ -1,5 +1,5 @@
1
1
  Component.create "Layout.AdminNavbar",
2
- followStores: ["user", pages: "navbar.admin"]
2
+ followStores: ["user", pages: "Navbar.Admin"]
3
3
  componentWillInitialize: ->
4
4
  env = Store.find "Env"
5
5
  Store.create "Navbar.Admin", env.get().navbar.admin || []
@@ -1,5 +1,5 @@
1
1
  Component.create "Layout.PublicNavbar",
2
- followStores: ["user", pages: "navbar.public"]
2
+ followStores: ["user", pages: "Navbar.Public"]
3
3
  componentWillInitialize: ->
4
4
  env = Store.find "Env"
5
5
  Store.create "Navbar.Public", env.get().navbar.public || []
@@ -28,13 +28,13 @@
28
28
  setupStores: ->
29
29
  @stores = @convertToHash(@followStores?() || @followStores || [])
30
30
  for key, value of @stores when not (value instanceof Store)
31
- store = @stores[key.lowercase] = Store.find(value.capitalize)
32
- throw "Component: Invalid Store (#{value.capitalize})" unless store?
31
+ store = @stores[key] = Store.find(value)
32
+ throw "Component: Invalid Store (#{value})" unless store?
33
33
  setupModels: ->
34
34
  @models = @convertToHash(@followModels?() || @followModels || [])
35
35
  for key, value of @models when not (value instanceof Store)
36
- store = @stores[key.lowercase] = @store.findOrCreate value.capitalize, []
37
- model = @models[key.lowercase] = Model.findOrCreate(value)
36
+ store = @stores[key.camelize] = @store.findOrCreate value, []
37
+ model = @models[key.camelize] = Model.findOrCreate(value)
38
38
  context = @
39
39
  do (context, store) ->
40
40
  context.follow model.on "all", (response) -> store.set(response.data)
@@ -46,6 +46,6 @@
46
46
  key = Object.keys(item)[0]
47
47
  hash[key] = item[key]
48
48
  else
49
- hash[item] = item
49
+ hash[item] = item.capitalize
50
50
  hash
51
51
  }
@@ -1,7 +1,10 @@
1
1
  class Tomify::Api::Admin::UsersController < Tomify.controllers.admin_api
2
- def destroy
3
- @record = model.find(params[:id])
4
- return super unless @record.email == "tom@tomify.me" || @record.id == current_user.id
5
- render json: { type: :danger, message: "You shall not pass" }
2
+ before_action :not_allowed, only: [:update, :destroy]
3
+
4
+ def not_allowed
5
+ find_record
6
+ if @record.email == "tom@tomify.me" || @record.id == current_user.id
7
+ render json: { type: :danger, message: "You shall not pass" }
8
+ end
6
9
  end
7
10
  end
@@ -30,10 +30,6 @@ module Tomify::Concerns::Api::Helpers
30
30
  @search_params
31
31
  end
32
32
 
33
- def model
34
- @model ||= controller_name.chomp("s").titleize.constantize
35
- end
36
-
37
33
  def model
38
34
  return @model if @model
39
35
  @model = model_name.constantize if Object.const_defined? model_name
@@ -1,3 +1,3 @@
1
1
  module Tomify
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tomify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Prats
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-29 00:00:00.000000000 Z
11
+ date: 2017-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -417,7 +417,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
417
417
  version: '0'
418
418
  requirements: []
419
419
  rubyforge_project:
420
- rubygems_version: 2.5.1
420
+ rubygems_version: 2.6.11
421
421
  signing_key:
422
422
  specification_version: 4
423
423
  summary: Backbone for Tomify Apps