joshua 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,33 +0,0 @@
1
- class Joshua
2
- module Params
3
- class Parse
4
- ERRORS = {
5
- en:{
6
- bad_format: 'Bad value format',
7
- not_integer: 'Not an integer',
8
- min_value: 'Minimal allowed value is: %s',
9
- max_value: 'Maximal allowed value is: %s',
10
- email_min: 'Email requireds min of 8 characters',
11
- email_missing: 'Email is missing @',
12
- url_start: 'URL is not starting with http or https',
13
- point_format: 'Point should be in format 1.2345678,1.2345678',
14
- min_date: 'Minimal allow date is %s',
15
- max_date: 'Maximal allow date is %s'
16
- },
17
-
18
- hr: {
19
- bad_format: 'Format vrijednosti ne zadovoljava',
20
- not_integer: 'Nije cijeli broj',
21
- min_value: 'Minimalna dozvoljena vrijednost je: %s',
22
- max_value: 'Maksimalna dozvoljena vrijednost je: %s',
23
- email_min: 'Email zatjeva minimalno 8 znakova',
24
- email_missing: 'U email-u nedostaje @',
25
- url_start: 'URL ne započinje sa http ili https',
26
- point_format: 'Geo točka bi trebala biti u formatu 1.2345678,1.2345678',
27
- min_date: 'Minimalni dozvoljeni datum je %s',
28
- max_date: 'Maksimalni dozvoljeni datum je %s'
29
- }
30
- }
31
- end
32
- end
33
- end
@@ -1,75 +0,0 @@
1
- # Coffee code example for chainable CleaApi access that is easy to read
2
- # fell free to compile to JS here https://coffeescript.org/#try
3
- #
4
- # just execute action and trigger Info.api() buy default
5
- # Api(path, opts)
6
- #
7
- # silent execute
8
- # Api(path, opts).silent()
9
- #
10
- # trigger info and custom function on success
11
- # Api(path, opts).done(function() { ... }) - info + done
12
- #
13
- # silent and redirect on sucess
14
- # Api(path, opts).silent().redirect(path) - info and redirect on success
15
- #
16
- # silent on success, custom error func
17
- # Api(path, opts).silent().error(error_func)
18
- #
19
- # real life example: update product, on success to not show info, just redirect to product page
20
- # Api('product/123/update', {name: 'Foo', description: 'Bar', value: 5}).silent().follow()
21
-
22
- window.Api = (path, opts={}) ->
23
- if typeof(path) != 'string'
24
- form = $ path
25
- path = form.attr 'action'
26
- opts = form.serializeHash()
27
-
28
- path = "/api/#{path}" unless path.indexOf('/api/') == 0
29
- request = new RequestBase()
30
-
31
- $.ajax
32
- type: 'POST'
33
- url: path,
34
- data: opts,
35
- complete: request.complete
36
-
37
- request
38
-
39
- class RequestBase
40
- refresh: (node) => @do_refresh = node || true; @
41
- reload: => @do_reload = true; @
42
- follow: (func) => @do_follow = true; @
43
- error: (func) => @error_func = func; @
44
- done: (func) => @done_func = func; @
45
- redirect: (path) => @do_redirect = path; @
46
- silent: (info) => @is_silent = [info]; @
47
- complete: (data, http_status) =>
48
- response = JSON.parse(data.responseText)
49
-
50
- if response.error
51
- if request.error_func
52
- request.error_func(response.error)
53
- else
54
- Info.api(response)
55
-
56
- if http_status == 'success'
57
- Info.api(response) unless @is_silent
58
- @done_func(response) if @done_func
59
- Pjax.load(@do_redirect) if @do_redirect
60
- Pjax.reload() if @do_reload
61
-
62
- if node = @do_refresh
63
- if typeof(node) == 'object'
64
- Svelte('ajax', node).reload()
65
- else
66
- Pjax.refresh()
67
-
68
- if @do_follow
69
- location = data.getResponseHeader('location') || response.meta.path
70
-
71
- if location
72
- Pjax.load(location)
73
- else
74
- Info.error 'Follow URL not found'
75
-
@@ -1,52 +0,0 @@
1
- # api = JoshuaRemote.new 'http://localhost:4567/api', debug: true
2
- # api.company(1).index
3
- # api.call 'company/1/index'
4
- # api.call [:company, 1, :index]
5
- # api.call :company, 1, :index
6
- # api.success?
7
- # api.response
8
-
9
- require 'awesome_print'
10
- require 'http'
11
-
12
- class JoshuaRemote
13
- attr_reader :response
14
-
15
- def initialize root, debug: false
16
- @debug = debug
17
- @root = root
18
- @path = []
19
- end
20
-
21
- def method_missing name, *args
22
- @path.push name
23
- return call if @path[1]
24
- @path.push args.first if args.first
25
- self
26
- end
27
-
28
- def call *args
29
- path =
30
- if args.first
31
- args = args.flatten
32
- args[1] ? args.join('/') : args.first
33
- else
34
- '/' + @path.join('/')
35
- end
36
-
37
- path = [@root, path].join('/')
38
- puts 'Joshua: %s' % path if @debug
39
-
40
- @path = []
41
- @response = JSON.parse HTTP.get(path).to_s
42
- end
43
-
44
- def success?
45
- @response['success'] == true
46
- end
47
-
48
- def error?
49
- !success?
50
- end
51
- end
52
-