tzispa_helpers 0.2.1 → 0.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2be7e36a5e2633854f4a42f8d2e0ec17252524c0
4
- data.tar.gz: e46332a07f2ae5c644b8faf60429789d70fa7c47
3
+ metadata.gz: b8d9b4d815e666c509beeb5c3c5b5446302c3a5f
4
+ data.tar.gz: ffd7c7ef51dcdbd5ab14078381ac1c93a5e3f23b
5
5
  SHA512:
6
- metadata.gz: 596891d7aa2dbbebcbc80eaa30dc234a75fdbbc58bc008979f2edfbf1914119aaaf99f760f0fc5e6c45d660ef7411b7e746392db1963c82a012fed10afae51e5
7
- data.tar.gz: cacb3395c8836b70f2afd50934d1e7225ee104bd7c20ba1db3a0377457e49b389adf94d76db58433f0d48473acac2043673381f589a0205ad8a366ce179ebb27
6
+ metadata.gz: b1702fe53fe07d1b9d5bff987f38ce1946e0a351e1d2e234441ff01462fc3dd8d9281b0eda134ab569d4950ed619dbb0ab0fa0010aa42c8df3e1bb9f18e53289
7
+ data.tar.gz: fde228365de640a6f7ea82fb86b2e133872f51e4242525668f0b15a30ea4279d23b6e3578fd93056c643d585b68282707bd9b228800bcdefdab2d30a04d8ce57
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  Tzispa Helpers
2
2
 
3
+ ## v0.2.2
4
+ - unscape html request form values
5
+ - added not_authorized alias method
6
+ - transform empty strings into nil for date/time methods
7
+ - bug fixes
8
+
3
9
  ## v0.2.1
4
10
  - added html_disabled helper method
5
11
 
@@ -1,9 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'tzispa/utils/string'
4
+
3
5
  module Tzispa
4
6
  module Helpers
5
7
  module Request
6
8
 
9
+ using Tzispa::Utils
10
+
7
11
  def request_data(fields)
8
12
  Hash.new.tap { |data|
9
13
  fields.each { |name|
@@ -13,7 +17,8 @@ module Tzispa
13
17
  field.split(':').tap { |fld|
14
18
  src = fld.first
15
19
  dest = fld.last
16
- data[dest.to_sym] = macro ? send(macro, context.request[src]) : context.request[src]
20
+ value = String == context.request[src] ? String.unescape_html(context.request[src]) : context.request[src]
21
+ data[dest.to_sym] = macro ? send(macro, value) : value
17
22
  }
18
23
  }
19
24
  }
@@ -28,7 +33,8 @@ module Tzispa
28
33
  field.split(':').tap { |fld|
29
34
  src = fld.first
30
35
  dest = fld.last
31
- data.send "#{dest}=".to_sym, macro ? send(macro, context.request[src]) : context.request[src]
36
+ value = String == context.request[src] ? String.unescape_html(context.request[src]) : context.request[src]
37
+ data.send "#{dest}=".to_sym, macro ? send(macro, value) : value
32
38
  }
33
39
  }
34
40
  }
@@ -41,21 +47,16 @@ module Tzispa
41
47
  save_ext = fileext if keep_ext
42
48
  filename = (save_as ? "#{save_as}#{save_ext}" : request_file[:filename])
43
49
  tempfile = request_file[:tempfile]
50
+ dest_file = "#{destination_path}/#{filename}"
44
51
  begin
45
- dest_file = "#{destination_path}/#{filename}"
52
+ FileUtils.mkdir_p(destination_path) unless File.exists?(destination_path)
46
53
  FileUtils.cp tempfile.path, dest_file
47
- result = { name: filename, ext: fileext, path: dest_file, size: ::File.size(dest_file), type: filetype }
48
- rescue => err
49
- context.logger.fatal(err) if context
50
- result = nil
51
54
  ensure
52
55
  tempfile.close
53
56
  tempfile.unlink
54
57
  end
55
- else
56
- result = nil
58
+ { name: filename, ext: fileext, path: dest_file, size: ::File.size(dest_file), type: filetype }
57
59
  end
58
- result
59
60
  end
60
61
 
61
62
 
@@ -95,6 +95,7 @@ module Tzispa
95
95
  def unauthorized(body = nil)
96
96
  error 401, body
97
97
  end
98
+ alias_method :not_authorized, :unauthorized
98
99
 
99
100
  # Set multiple response headers with Hash.
100
101
  def headers(hash = nil)
@@ -150,7 +151,7 @@ module Tzispa
150
151
  result[1].each { |k,v| response.headers[k] ||= v }
151
152
  response.headers['Content-Length'] = result[1]['Content-Length']
152
153
  response.status = result[0]
153
- response.body = result[2]
154
+ response.body = result[2]
154
155
  rescue
155
156
  not_found 'Fichero no encontrado'
156
157
  end
@@ -62,20 +62,13 @@ module Tzispa
62
62
  end
63
63
 
64
64
  def str_to_date(str, format=nil)
65
- begin
66
- Date.strptime(str, format || I18n.t('date.formats.default')) if str
67
- rescue
68
- nil
69
- end
65
+ str = strip_to_nil str
66
+ Date.strptime(str, format || I18n.t('date.formats.default')) if str
70
67
  end
71
68
 
72
69
  def str_to_datetime(str, format=nil)
73
- begin
74
- result = DateTime.strptime(str, format || I18n.t('time.formats.default'))
75
- rescue
76
- result = nil
77
- end
78
- result
70
+ str = strip_to_nil str
71
+ DateTime.strptime(str, format || I18n.t('datetime.formats.default'))
79
72
  end
80
73
 
81
74
  def str_time_ellapsed(t_start, t_end=nil)
@@ -3,7 +3,7 @@
3
3
  module Tzispa
4
4
  module Helpers
5
5
 
6
- VERSION = '0.2.1'
6
+ VERSION = '0.2.2'
7
7
  NAME = 'Tzispa Helpers'
8
8
  GEM_NAME = 'tzispa_helpers'
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tzispa_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Antonio Piñero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-28 00:00:00.000000000 Z
11
+ date: 2017-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.7'
19
+ version: '0.8'
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: '0.7'
26
+ version: '0.8'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: unicode_utils
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tzispa_utils
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.3'
41
55
  description: Module Helpers for Tzispa framework
42
56
  email:
43
57
  - japinero@area-integral.com
@@ -83,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
97
  version: '0'
84
98
  requirements: []
85
99
  rubyforge_project:
86
- rubygems_version: 2.5.2
100
+ rubygems_version: 2.6.10
87
101
  signing_key:
88
102
  specification_version: 4
89
103
  summary: Helpers for Tzispa