tzispa_helpers 0.1.21 → 0.2.0

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: f5bc6f2d8bd4235851b213da834c4e50f0440dab
4
- data.tar.gz: dbd91908bec6fe96a8bda0530e24c56270bf9993
3
+ metadata.gz: 9e2be3edcd4a149c92a495c95ad29b11361af0a1
4
+ data.tar.gz: ed24d3d6fc981ea012549824ac070b02ce09689f
5
5
  SHA512:
6
- metadata.gz: f976cd43680ca151dbdea5a5b500255a03099f832b36c9a179b3e6c6e8cd3cc2b654be3e43a1d8690a003c8814f6d386af2b2ca659fbb096c4d3b604f644b922
7
- data.tar.gz: 97615ff3c0a3bdc9c51c1ba0e1f44782d62a87c50511412d0186a82c46f5a410919a22e99fdf99b6aba71c924eccd8b06cbac910d9a9e7f3fba702855040029f
6
+ metadata.gz: 8275f67c742d2cac0f20be27ffbd3f3818d8b638b291dde0b82e9da782e5d93b63c8e3e89ae06979c55aa1840e4f2a06ff93a4b4ca3b8411ec5d5212cff9c1d8
7
+ data.tar.gz: 58d20abb7e376fc1c9bd979a27a9830ed3cfca5c996c2d8f0f12aedbf090debcf57e77e14f295bd54aa2bddee173c3493800d52d1753079e52c1cab05ed8d023
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  Tzispa Helpers
2
2
 
3
+ ## v0.2.0
4
+ - move some helpers to experts avoiding excesive gem dependencies
5
+
3
6
  ## v0.1.21
4
7
  - added requirer and sign_requirer dsl helpers
5
8
  - added provider dsl helper
@@ -4,7 +4,6 @@ require 'date'
4
4
  require 'bigdecimal'
5
5
  require 'i18n'
6
6
  require "unicode_utils"
7
- require 'redcarpet'
8
7
  require 'cgi/util'
9
8
 
10
9
  module Tzispa
@@ -160,15 +159,6 @@ module Tzispa
160
159
  amount(number, options.merge(:nil_as_dash => false, :precision => I18n.t('number.currency.format.precision'), minimum_precision: 0))
161
160
  end
162
161
 
163
- def mime_formatter(text, mime)
164
- case mime
165
- when 'text/x-markdown'
166
- Redcarpet::Markdown.new(Redcarpet::Render::HTML.new).render(text) if text
167
- else
168
- text
169
- end
170
- end
171
-
172
162
  def starinizer(rating, star_value, max_stars)
173
163
  Hash.new.tap { |stars|
174
164
  stars[:full] = rating / star_value
@@ -3,7 +3,7 @@
3
3
  module Tzispa
4
4
  module Helpers
5
5
 
6
- VERSION = '0.1.21'
6
+ VERSION = '0.2.0'
7
7
  NAME = 'Tzispa Helpers'
8
8
  GEM_NAME = 'tzispa_helpers'
9
9
 
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tzispa_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.2.0
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-10-31 00:00:00.000000000 Z
11
+ date: 2016-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: mail
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.6'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '2.6'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: i18n
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -52,34 +38,6 @@ dependencies:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
40
  version: '1.4'
55
- - !ruby/object:Gem::Dependency
56
- name: redcarpet
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.3'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3.3'
69
- - !ruby/object:Gem::Dependency
70
- name: nokogiri
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.6'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.6'
83
41
  description: Module Helpers for Tzispa framework
84
42
  email:
85
43
  - japinero@area-integral.com
@@ -90,16 +48,13 @@ files:
90
48
  - CHANGELOG.md
91
49
  - README.md
92
50
  - lib/tzispa/helpers.rb
93
- - lib/tzispa/helpers/crawler.rb
94
51
  - lib/tzispa/helpers/date_time.rb
95
52
  - lib/tzispa/helpers/error_view.rb
96
53
  - lib/tzispa/helpers/hash_trans.rb
97
54
  - lib/tzispa/helpers/html.rb
98
- - lib/tzispa/helpers/mail.rb
99
55
  - lib/tzispa/helpers/mime.rb
100
56
  - lib/tzispa/helpers/pattern.rb
101
57
  - lib/tzispa/helpers/provider.rb
102
- - lib/tzispa/helpers/recaptcha.rb
103
58
  - lib/tzispa/helpers/request.rb
104
59
  - lib/tzispa/helpers/requirer.rb
105
60
  - lib/tzispa/helpers/response.rb
@@ -1,136 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'open-uri'
4
- require 'nokogiri'
5
- require 'htmlentities'
6
- require 'reverse_markdown'
7
- require 'unicode_utils'
8
- require 'redcarpet'
9
- require 'tzispa/helpers/hash_trans'
10
-
11
- module Tzispa
12
- module Helpers
13
- module Crawler
14
-
15
- include Tzispa::Helpers::HashTrans
16
-
17
- class CrawlerError < StandardError; end
18
-
19
-
20
- def crawler_save_file(url, dest_file, accept_schemes = ['http', 'https', 'ftp'])
21
- begin
22
- uri = URI(url)
23
- raise ArgumentError.new "Inavlid url: #{url}" unless accept_schemes.include?(uri.scheme) && uri.host
24
- File.delete(dest_file) if File.exist?(dest_file)
25
- File.open("#{dest_file}", 'wb') do |fo|
26
- fo.write open(url).read
27
- end
28
- rescue => ex
29
- raise CrawlerError.new "Error in crawler_save_file '#{url}': #{ex.message}"
30
- end
31
- end
32
-
33
- def crawler_to_markdown(source)
34
- begin
35
- source = source.read if source.respond_to? :read
36
- htmee = HTMLEntities.new
37
- ReverseMarkdown.convert(htmee.decode(source).strip, unknown_tags: :bypass)
38
- rescue Encoding::UndefinedConversionError
39
- end
40
- end
41
-
42
- def crawler_table_to_dl(noko, table_path, columns, excluded_terms: [], fussion_terms:{})
43
- String.new.tap { |content|
44
- markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new)
45
- sections = crawler_table(noko, table_path, columns)
46
- hash_fussion! sections, fussion_terms
47
- unless sections.empty?
48
- content << '<dl>'
49
- sections.sort.each { |key, value|
50
- unless key.empty? || value.empty? || excluded_terms.include?(UnicodeUtils.downcase key)
51
- content << "<dt>#{key}</dt>"
52
- if value.is_a?(Array) && value.count > 1
53
- content << '<ul>' << value.map { |item| "<li>#{markdown.render item}</li>"}.join("\n") << '</ul>'
54
- elsif value.is_a?(Array) && value.count == 1
55
- content << "<dd>#{markdown.render value.first}</dd>"
56
- else
57
- content << "<dd>#{markdown.render value}</dd>"
58
- end
59
- end
60
- }
61
- content << "</dl>"
62
- end
63
- }
64
- end
65
-
66
- def crawler_table(noko, table_path, columns)
67
- Hash.new.tap { |sections|
68
- htmee = HTMLEntities.new(:expanded)
69
- noko = noko.xpath(table_path)
70
- colspans = "td[@colspan=\"#{columns}\"]"
71
- if noko.xpath(colspans).count == 0
72
- noko.collect { |row|
73
- dterm = htmee.decode(row.at_xpath('td[1]')&.content).gsub(/\n|\r|\t/,' ').strip
74
- unless dterm.empty?
75
- sections[dterm] ||= Array.new
76
- sections[dterm] << (2..columns).map { |i|
77
- ReverseMarkdown.convert(
78
- htmee.decode(row.at_xpath("td[#{i}]")&.children&.to_s || row.at_xpath("td[#{i}]")&.to_s).strip, unknown_tags: :bypass
79
- ).gsub(/\r|\t/,' ').strip
80
- }.join('\n')
81
- end
82
- }
83
- else
84
- current_section = nil
85
- noko.collect { |row|
86
- unless row.xpath(colspans)&.text.strip.empty?
87
- current_section = htmee.decode(row.xpath("td[@colspan=\"#{columns}\"]").text).gsub(/\n|\r|\t/,' ').strip
88
- sections[current_section] ||= Array.new
89
- else
90
- if current_section
91
- sections[current_section] << (1..columns).map { |i|
92
- ReverseMarkdown.convert(
93
- htmee.decode(row.at_xpath("td[#{i}]")&.children&.to_s.strip || row.at_xpath("td[#{i}]")&.to_s.strip), unknown_tags: :bypass
94
- ).strip
95
- }.join(': ')
96
- end
97
- end
98
- }
99
- end
100
- }
101
- end
102
-
103
- def crawler_table_to_list(noko, table_path, excluded_terms: [])
104
- htmee = HTMLEntities.new(:expanded)
105
- markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new)
106
- String.new.tap { |list|
107
- list << '<ul>'
108
- list << Array.new.tap { |lines|
109
- noko.xpath(table_path).collect { |td|
110
- line = if td.xpath('table/tr/td').count > 0
111
- crawler_table(td, 'table/tr', 2)
112
- else
113
- raw_ln = ReverseMarkdown.convert(td&.children&.to_s.strip, unknown_tags: :bypass)
114
- raw_ln unless raw_ln.empty? || excluded_terms.include?(raw_ln)
115
- end
116
- if line&.is_a? String
117
- lines << "<li>#{htmee.decode(markdown.render line)}</li>"
118
- elsif line.is_a? Hash
119
- line&.map { |key, value|
120
- lines << "<li><strong>#{key}</strong>: #{value} </li>" unless excluded_terms.include?(key) || excluded_terms.include?(value)
121
- }.join("\n")
122
- else
123
- line&.map { |v|
124
- lines << "<li>#{v}</li>" unless excluded_terms.include?(v)
125
- }.join("\n")
126
- end
127
- }
128
- }.join("\n")
129
- list << '</ul>'
130
- }
131
- end
132
-
133
-
134
- end
135
- end
136
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'mail'
4
-
5
- module Tzispa
6
- module Helpers
7
- module Mail
8
-
9
- def send_smtp_mail(from:, to:, subject:, body:, config:, cc: nil, html: false, debug: false, charset: 'UTF-8')
10
- begin
11
- smtp_configuration config
12
- mail = ::Mail.new
13
- mail.from = from
14
- if !to.empty?
15
- to_addrs = to.split(';')
16
- mail.to = to_addrs.pop
17
- to_addrs.each { |email|
18
- mail.to << email
19
- }
20
- if cc
21
- cc_addrs = cc.split(';')
22
- mail.cc = cc_addrs.pop
23
- cc_addrs.each { |email|
24
- mail.cc << email
25
- }
26
- end
27
- mail.subject = subject
28
- if html
29
- mail.html_part do
30
- content_type "text/html; charset=#{charset}"
31
- body = body
32
- end
33
- else
34
- mail.body = body
35
- end
36
- mail.charset = charset
37
- mail.deliver
38
- else
39
- nil
40
- end
41
- rescue
42
- raise if debug
43
- end
44
- end
45
-
46
- private
47
-
48
- def smtp_configuration(config)
49
- if config.smtp_auth
50
- ::Mail.defaults do
51
- delivery_method :smtp, address: config.host, domain: config.domain,
52
- port: config.port, authentication: config.authentication,
53
- openssl_verify_mode: config.openssl_verify, enable_starttls_auto: config.starttls_auto,
54
- user_name: config.user_name, password: config.password
55
- end
56
- else
57
- ::Mail.defaults do
58
- delivery_method :smtp, address: config.host, domain: config.domain,
59
- port: config.port, openssl_verify_mode: config.openssl_verify,
60
- enable_starttls_auto: config.starttls_auto
61
- end
62
- end
63
- end
64
-
65
-
66
-
67
- end
68
- end
69
- end
@@ -1,30 +0,0 @@
1
- require 'net/http'
2
-
3
- module Tzispa
4
- module Helpers
5
- module Recaptcha
6
-
7
- RECAPTCHA_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'
8
- RECAPTCHA_RESPONSE_FIELD = 'g-recaptcha-response'
9
-
10
- def verify(secret, response, ip)
11
- params = {
12
- 'secret': secret,
13
- 'response': response,
14
- 'remoteip': ip
15
- }
16
-
17
- uri = URI.parse(RECAPTCHA_VERIFY_URL)
18
- http = Net::HTTP.start(uri.host, uri.port)
19
-
20
- request = Net::HTTP::Post.new(uri.path)
21
- request.form_data = params
22
- response = http.request(request)
23
-
24
- JSON.parse response.body
25
- end
26
-
27
-
28
- end
29
- end
30
- end