ultimate-base 0.3.5.0 → 0.4.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ultimate-base (0.3.5.0)
4
+ ultimate-base (0.4.0.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,5 +1,5 @@
1
1
  module Ultimate
2
2
  module Base
3
- VERSION = "0.3.5.0"
3
+ VERSION = '0.4.0.0'
4
4
  end
5
5
  end
@@ -5,9 +5,4 @@
5
5
  #= require_tree ./tests/underscore
6
6
  #= require_tree ./tests/improves
7
7
  #
8
- #= require ./tests/helpers/tag_test
9
- #= require ./tests/helpers/record_tag_test
10
- #= require ./tests/helpers/asset_tag_test
11
- #= require ./tests/helpers/url_test
12
- #
13
8
  #= require_tree ./tests
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ultimate-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5.0
4
+ version: 0.4.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -89,16 +89,6 @@ files:
89
89
  - app/assets/javascripts/ultimate/experimental/_inflections/plur.js
90
90
  - app/assets/javascripts/ultimate/experimental/fuzzy-json-generator.js.coffee
91
91
  - app/assets/javascripts/ultimate/helpers.js.coffee
92
- - app/assets/javascripts/ultimate/helpers/asset_tag.js.coffee
93
- - app/assets/javascripts/ultimate/helpers/base.js.coffee
94
- - app/assets/javascripts/ultimate/helpers/decor.js.coffee
95
- - app/assets/javascripts/ultimate/helpers/form_options.js.coffee
96
- - app/assets/javascripts/ultimate/helpers/form_tag.js.coffee
97
- - app/assets/javascripts/ultimate/helpers/javascript.js.coffee
98
- - app/assets/javascripts/ultimate/helpers/number.js.coffee
99
- - app/assets/javascripts/ultimate/helpers/record_tag.js.coffee
100
- - app/assets/javascripts/ultimate/helpers/tag.js.coffee
101
- - app/assets/javascripts/ultimate/helpers/url.js.coffee
102
92
  - app/assets/javascripts/ultimate/improves/datepicker.js.coffee
103
93
  - app/assets/javascripts/ultimate/improves/devise.js.coffee
104
94
  - app/assets/javascripts/ultimate/improves/form-errors.js.coffee
@@ -184,14 +174,6 @@ files:
184
174
  - test/javascripts/all_tests.js.coffee
185
175
  - test/javascripts/test_helper.js.coffee
186
176
  - test/javascripts/tests/base_test.js.coffee
187
- - test/javascripts/tests/helpers/asset_tag_test.js.coffee
188
- - test/javascripts/tests/helpers/form_options_test.js.coffee
189
- - test/javascripts/tests/helpers/form_tag_test.js.coffee
190
- - test/javascripts/tests/helpers/javascript_test.js.coffee
191
- - test/javascripts/tests/helpers/number_test.js.coffee
192
- - test/javascripts/tests/helpers/record_tag_test.js.coffee
193
- - test/javascripts/tests/helpers/tag_test.js.coffee
194
- - test/javascripts/tests/helpers/url_test.js.coffee
195
177
  - test/javascripts/tests/helpers_test.js.coffee
196
178
  - test/javascripts/tests/improves/i18n-lite_test.js.coffee
197
179
  - test/javascripts/tests/jquery-plugin-adapter_test.js.coffee
@@ -1,82 +0,0 @@
1
- #= require ./base
2
- #= require ./tag
3
-
4
- @Ultimate.Helpers.AssetTag =
5
-
6
- favicon_link_tag: (source = 'favicon.ico', options = {}) ->
7
- tag 'link', _.extend
8
- rel: 'shortcut icon'
9
- type: 'image/vnd.microsoft.icon'
10
- href: @path_to_image(source)
11
- , options
12
-
13
- image_path: (source) ->
14
- if source then @compute_public_path(source, 'images') else ''
15
-
16
- path_to_image: -> @image_path arguments... # aliased to avoid conflicts with an image_path named route
17
-
18
- image_tag: (source, options = {}) ->
19
- src = options['src'] = @path_to_image(source)
20
- if _.isUndefined(options['alt']) and src and not /^(?:cid|data):/.test(src)
21
- options['alt'] = @image_alt(src)
22
- if size = _.outcasts.delete(options, 'size')
23
- if matches = size.match(/^(\d+)x(\d+)$/)
24
- options['width'] = matches[1]
25
- options['height'] = matches[2]
26
- else if /^(\d+)$/.test(size)
27
- options['width'] = options['height'] = size
28
- Ultimate.Helpers.Tag.tag('img', options)
29
-
30
- image_alt: (src) ->
31
- _.string.capitalize @_without_extension(@_basename(src)).replace(/-[A-Fa-f0-9]{32}/, '')
32
-
33
-
34
-
35
- # ===================== AssetPaths =====================
36
-
37
- URI_REGEXP: /^[-a-z]+:\/\/|^(?:cid|data):|^\/\//
38
-
39
- is_uri: (path) ->
40
- @URI_REGEXP.test(path)
41
-
42
- RELATIVE_URL_ROOT: ''
43
-
44
- compute_public_path: (source, dir, options = {}) ->
45
- return source if @is_uri(source)
46
- source = @_rewrite_extension(source, options['ext']) if options['ext']
47
- source = @_rewrite_asset_path(source, dir)
48
- source = @_rewrite_relative_url_root(source, @RELATIVE_URL_ROOT)
49
- source
50
-
51
- _rewrite_extension: (source, ext) ->
52
- "#{@_without_extension(source)}.#{ext}"
53
-
54
- _without_extension: (source) ->
55
- source.replace(/^(.+)(\.\w+)$/, '$1')
56
-
57
- _ASSET_ID: ''
58
- _asset_ids_cache: {}
59
- # Use the ASSET_ID inscope variable or the random hash as its cache-busting asset id.
60
- _asset_id: (source) ->
61
- if _.isString(@_ASSET_ID)
62
- @_ASSET_ID
63
- else
64
- @_asset_ids_cache[source] or (@_asset_ids_cache[source] = 10000000 + Math.floor(Math.random() * 90000000))
65
-
66
- # Break out the asset path rewrite in case plugins wish to put the asset id
67
- # someplace other than the query string.
68
- _rewrite_asset_path: (source, dir) ->
69
- source = "/#{dir}/#{source}" unless source[0] is '/'
70
- if id = @_asset_id(source)
71
- "#{source}?#{id}"
72
- else
73
- source
74
-
75
- _rewrite_relative_url_root: (source, relative_url_root) ->
76
- if relative_url_root and not _.startsWith(source, "#{relative_url_root}/")
77
- "#{relative_url_root}#{source}"
78
- else
79
- source
80
-
81
- _basename: (source) ->
82
- source = matches[2] if matches = source.match(/^(.*\/)?(.+)?$/)
@@ -1,3 +0,0 @@
1
- #= require ultimate/base
2
-
3
- @Ultimate.Helpers ||= {}
@@ -1,19 +0,0 @@
1
- #= require ./base
2
- #= require ./tag
3
-
4
- @Ultimate.Helpers.Decor =
5
-
6
- g_decor_body: (tag, inner) ->
7
- content_tag(tag, '', class: 'left') +
8
- content_tag(tag, '', class: 'right') +
9
- content_tag(tag, inner, class: 'fill')
10
-
11
- g_star_decor_body: (tag, inner) ->
12
- content_tag(tag, inner, class: 'wrapper') +
13
- content_tag(tag, '', class: 'corner left top') +
14
- content_tag(tag, '', class: 'corner right top') +
15
- content_tag(tag, '', class: 'corner left bottom') +
16
- content_tag(tag, '', class: 'corner right bottom')
17
-
18
- g_wrapper_decor_body: (tag, inner) ->
19
- content_tag tag, inner, class: 'wrapper'
@@ -1,106 +0,0 @@
1
- #= require ./base
2
- #= require ./tag
3
-
4
- @Ultimate.Helpers.FormOptions =
5
-
6
- options_for_select: (container, selected = null) ->
7
- return container if _.isString(container)
8
- [selected, disabled] = _.map @_extract_selected_and_disabled(selected), (r) ->
9
- _.map _.outcasts.arrayWrap(r), (item) -> item.toString()
10
- container = _.pairs(container) if $.isPlainObject(container)
11
- _.map(container, (element) ->
12
- html_attributes = @_option_html_attributes(element)
13
- [text, value] = _.map @_option_text_and_value(element), (item) -> if item? then item.toString() else ''
14
- html_attributes['value'] = value
15
- html_attributes['selected'] = 'selected' if @_option_value_selected(value, selected)
16
- html_attributes['disabled'] = 'disabled' if disabled and @_option_value_selected(value, disabled)
17
- Ultimate.Helpers.Tag.content_tag_string 'option', text, html_attributes
18
- ).join("\n")
19
-
20
- options_from_collection_for_select: (collection, value_method, text_method, selected = null) ->
21
- options = @__mapCollection collection, (element) ->
22
- [@_value_for_collection(element, text_method), @_value_for_collection(element, value_method)]
23
- [selected, disabled] = @_extract_selected_and_disabled(selected)
24
- select_deselect =
25
- selected: @_extract_values_from_collection(collection, value_method, selected)
26
- disabled: @_extract_values_from_collection(collection, value_method, disabled)
27
- @options_for_select(options, select_deselect)
28
-
29
- option_groups_from_collection_for_select: (collection, group_method, group_label_method, option_key_method, option_value_method, selected_key = null) ->
30
- @__mapCollection(collection, (group) ->
31
- option_tags = @options_from_collection_for_select(_.result(group, group_method), option_key_method, option_value_method, selected_key)
32
- Ultimate.Helpers.Tag.content_tag_string 'optgroup', option_tags, label: _.result(group, group_label_method), true, false
33
- ).join('')
34
-
35
- grouped_options_for_select: (grouped_options, selected_key = null, options = {}) ->
36
- prompt = options['prompt']
37
- divider = options['divider']
38
- body = ""
39
- if prompt
40
- body += Ultimate.Helpers.Tag.content_tag_string('option', @_prompt_text(prompt), value: '')
41
- grouped_options = _.outcasts.sortHash(grouped_options) if $.isPlainObject(grouped_options)
42
- _.each grouped_options, (container) ->
43
- if divider
44
- label = divider
45
- else
46
- [label, container] = container
47
- body += Ultimate.Helpers.Tag.content_tag_string('optgroup', @options_for_select(container, selected_key), label: label, true, false)
48
- body
49
-
50
-
51
-
52
- _option_html_attributes: (element) ->
53
- result = {}
54
- if _.isArray(element)
55
- _.extend(result, e) for e in element when $.isPlainObject(e)
56
- result
57
-
58
- _option_text_and_value: (option) ->
59
- # Options are [text, value] pairs or strings used for both.
60
- if _.isArray(option)
61
- option = _.reject(option, (e) -> $.isPlainObject(e))
62
- [_.first(option), _.last(option)]
63
- else
64
- [option, option]
65
-
66
- _option_value_selected: (value, selected) ->
67
- value in selected
68
-
69
- _extract_selected_and_disabled: (selected) ->
70
- if _.isFunction(selected)
71
- [selected, null]
72
- else
73
- selected = _.outcasts.arrayWrap(selected)
74
- options = if $.isPlainObject(_.last(selected)) then selected.pop() else {}
75
- selected_items = options['selected'] ? selected
76
- [selected_items, options['disabled']]
77
-
78
- _extract_values_from_collection: (collection, value_method, selected) ->
79
- if _.isFunction(selected)
80
- _.compact @__mapCollection collection, (element) ->
81
- @__getValueFromElement(element, value_method) if selected(element)
82
- else
83
- selected
84
-
85
- _value_for_collection: (item, value) ->
86
- if _.isFunction(value)
87
- value(item)
88
- else
89
- @__getValueFromElement(item, value)
90
-
91
- _prompt_text: (prompt) ->
92
- prompt = if _.isString(prompt) then prompt else I18n?.translate('helpers.select.prompt', default: 'Please select') ? 'Please select'
93
-
94
-
95
-
96
- __getValueFromElement: (element, property) ->
97
- if _.isFunction(element.get)
98
- element.get(property)
99
- else
100
- _.result(element, property)
101
-
102
- __mapCollection: (collection, iterator) ->
103
- if _.isFunction(collection.map)
104
- collection.map(iterator)
105
- else
106
- _.map(collection, iterator)
@@ -1,175 +0,0 @@
1
- #= require ./base
2
- #= require ./tag
3
- #= require ./url
4
- #= require ./asset_tag
5
-
6
- @Ultimate.Helpers.FormTag =
7
-
8
- embed_authenticity_token_in_remote_forms: false
9
-
10
- form_tag: (url_for_options = {}, options = {}, block = null) ->
11
- html_options = @_html_options_for_form(url_for_options, options)
12
- if block = _.outcasts.blockGiven(arguments)
13
- @_form_tag_in_block(html_options, block)
14
- else
15
- @_form_tag_html(html_options)
16
-
17
- select_tag: (name, option_tags = '', options = {}) ->
18
- html_name = if options.multiple is true and not _.string.endsWith(name, '[]') then "#{name}[]" else name
19
- if _.outcasts.delete(options, 'include_blank')
20
- option_tags = Ultimate.Helpers.Tag.content_tag('option', '', value: '') + option_tags
21
- if prompt = _.outcasts.delete(options, 'prompt')
22
- option_tags = Ultimate.Helpers.Tag.content_tag('option', prompt, value: '') + option_tags
23
- Ultimate.Helpers.Tag.content_tag 'select', option_tags, _.extend({name: html_name, id: @_sanitize_to_id(name)}, options), false
24
-
25
- text_field_tag: (name, value = null, options = {}) ->
26
- Ultimate.Helpers.Tag.tag 'input', _.extend({type: 'text', name: name, id: @_sanitize_to_id(name), value: value}, options)
27
-
28
- label_tag: (name = null, content_or_options = null, options = null, block = null) ->
29
- if block = _.outcasts.blockGiven(arguments)
30
- [options, content_or_options] = [content_or_options, block()]
31
- options ||= {}
32
- if _.isString(name) and not _.string.isBlank(name)
33
- unless _.has(options, 'for')
34
- options = _.clone(options)
35
- options['for'] = @_sanitize_to_id(name)
36
- content_or_options ||= _.string.humanize(name)
37
- Ultimate.Helpers.Tag.content_tag_string 'label', content_or_options, options, true, false
38
-
39
- hidden_field_tag: (name, value = null, options = {}) ->
40
- @text_field_tag name, value, _.extend(options, type: 'hidden')
41
-
42
- file_field_tag: (name, options = {}) ->
43
- @text_field_tag name, null, _.extend(options, type: 'file')
44
-
45
- password_field_tag: (name = 'password', value = null, options = {}) ->
46
- @text_field_tag name, value, _.extend(options, type: 'password')
47
-
48
- text_area_tag: (name, content = null, options = {}) ->
49
- if size = _.outcasts.delete(options, 'size')
50
- [options['cols'], options['rows']] = size.split("x") if _.isFunction(size.split)
51
- escape = _.outcasts.delete(options, 'escape') ? true
52
- Ultimate.Helpers.Tag.content_tag 'textarea', content, _.extend({name: name, id: @_sanitize_to_id(name)}, options), escape
53
-
54
- check_box_tag: (name, value = '1', checked = false, options = {}) ->
55
- html_options = _.extend({type: 'checkbox', name: name, id: @_sanitize_to_id(name), value: value}, options)
56
- html_options['checked'] = 'checked' if checked
57
- Ultimate.Helpers.Tag.tag 'input', html_options
58
-
59
- radio_button_tag: (name, value, checked = false, options = {}) ->
60
- html_options = _.extend({type: 'radio', name: name, id: "#{@_sanitize_to_id(name)}_#{@_sanitize_to_id(value)}", value: value}, options)
61
- html_options['checked'] = 'checked' if checked
62
- Ultimate.Helpers.Tag.tag 'input', html_options
63
-
64
- submit_tag: (value = 'Save changes', options = {}) ->
65
- Ultimate.Helpers.Tag.tag 'input', _.extend({type: 'submit', name: 'commit', value: value}, options)
66
-
67
- button_tag: (content_or_options = null, options = null, block = null) ->
68
- options = content_or_options if (block = _.outcasts.blockGiven(arguments)) and $.isPlainObject(content_or_options)
69
- options ||= {}
70
- options = _.extend({name: 'button', type: 'submit'}, options)
71
- content_or_options = options if block
72
- Ultimate.Helpers.Tag.content_tag 'button', content_or_options ? 'Button', options, not block, block
73
-
74
- image_submit_tag: (source, options = {}) ->
75
- Ultimate.Helpers.Tag.tag 'input', _.extend({type: 'image', src: Ultimate.Helpers.AssetTag.path_to_image(source)}, options)
76
-
77
- field_set_tag: (legend = null, options = null, block) ->
78
- output = Ultimate.Helpers.Tag.tag('fieldset', options, true)
79
- output += Ultimate.Helpers.Tag.content_tag('legend', legend) if _.isString(legend) and not _.string.isBlank(legend)
80
- output += block() if block = _.outcasts.blockGiven(arguments)
81
- output += '</fieldset>'
82
- output
83
-
84
- color_field_tag: (name, value = null, options = {}) ->
85
- @text_field_tag name, value, _.extend(options, type: 'color')
86
-
87
- search_field_tag: (name, value = null, options = {}) ->
88
- @text_field_tag name, value, _.extend(options, type: 'search')
89
-
90
- telephone_field_tag: (name, value = null, options = {}) ->
91
- @text_field_tag name, value, _.extend(options, type: 'tel')
92
-
93
- phone_field_tag: ->
94
- @telephone_field_tag arguments...
95
-
96
- date_field_tag: (name, value = null, options = {}) ->
97
- @text_field_tag name, value, _.extend(options, type: 'date')
98
-
99
- time_field_tag: (name, value = null, options = {}) ->
100
- @text_field_tag name, value, _.extend(options, type: 'time')
101
-
102
- datetime_field_tag: (name, value = null, options = {}) ->
103
- @text_field_tag name, value, _.extend(options, type: 'datetime')
104
-
105
- datetime_local_field_tag: (name, value = null, options = {}) ->
106
- @text_field_tag name, value, _.extend(options, type: 'datetime-local')
107
-
108
- month_field_tag: (name, value = null, options = {}) ->
109
- @text_field_tag name, value, _.extend(options, type: 'month')
110
-
111
- week_field_tag: (name, value = null, options = {}) ->
112
- @text_field_tag name, value, _.extend(options, type: 'week')
113
-
114
- url_field_tag: (name, value = null, options = {}) ->
115
- @text_field_tag name, value, _.extend(options, type: 'url')
116
-
117
- email_field_tag: (name, value = null, options = {}) ->
118
- @text_field_tag name, value, _.extend(options, type: 'email')
119
-
120
- number_field_tag: (name, value = null, options = {}) ->
121
- options['type'] ||= 'number'
122
- if range = _.outcasts.delete(options, 'in') or _.outcasts.delete(options, 'within')
123
- _.extend options, min: range.min, max: range.max
124
- @text_field_tag name, value, options
125
-
126
- range_field_tag: (name, value = null, options = {}) ->
127
- @number_field_tag name, value, _.extend(options, type: 'range')
128
-
129
- utf8_enforcer_tag: ->
130
- Ultimate.Helpers.Tag.tag 'input', type: 'hidden', name: 'utf8', value: '&#x2713;', false, false
131
-
132
- _html_options_for_form: (url_for_options, options) ->
133
- html_options = options
134
- html_options['enctype'] = 'multipart/form-data' if _.outcasts.delete(html_options, 'multipart')
135
- # The following URL is unescaped, this is just a hash of options, and it is the
136
- # responsibility of the caller to escape all the values.
137
- html_options['action'] = Ultimate.Helpers.Url.url_for(url_for_options)
138
- html_options['accept-charset'] = 'UTF-8'
139
- html_options['data-remote'] = true if _.outcasts.delete(html_options, 'remote')
140
- if html_options['data-remote'] and
141
- not @embed_authenticity_token_in_remote_forms and
142
- _.string.isBlank(html_options['authenticity_token'])
143
- # The authenticity token is taken from the meta tag in this case
144
- html_options['authenticity_token'] = false
145
- else if html_options['authenticity_token'] is true
146
- # Include the default authenticity_token, which is only generated when its set to nil,
147
- # but we needed the true value to override the default of no authenticity_token on data-remote.
148
- html_options['authenticity_token'] = null
149
- html_options
150
-
151
- _extra_tags_for_form: (html_options) ->
152
- authenticity_token = _.outcasts.delete(html_options, 'authenticity_token')
153
- method = _.outcasts.delete(html_options, 'method')
154
- method_tag =
155
- if /^get$/i.test(method) # must be case-insensitive, but can't use downcase as might be nil
156
- html_options['method'] = 'get'
157
- ''
158
- else if _.string.isBlank(method) or /^post$/i.test(method)
159
- html_options['method'] = 'post'
160
- Ultimate.Helpers.Url._token_tag(authenticity_token)
161
- else
162
- html_options['method'] = 'post'
163
- Ultimate.Helpers.Url._method_tag(method) + Ultimate.Helpers.Url._token_tag(authenticity_token)
164
- tags = @utf8_enforcer_tag() + method_tag
165
- Ultimate.Helpers.Tag.content_tag('div', tags, style: 'margin:0;padding:0;display:inline', false)
166
-
167
- _form_tag_html: (html_options) ->
168
- extra_tags = @_extra_tags_for_form(html_options)
169
- Ultimate.Helpers.Tag.tag('form', html_options, true) + extra_tags
170
-
171
- _form_tag_in_block: (html_options, block) ->
172
- "#{@_form_tag_html(html_options)}#{block()}</form>"
173
-
174
- _sanitize_to_id: (name) ->
175
- if name? then name.toString().replace(/\]/g, '').replace(/[^-a-zA-Z0-9:.]/g, '_') else ''