starlight_helpers 0.1000 → 0.1001
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 +4 -4
- data/lib/starlight_helpers.rb +1 -0
- data/lib/starlight_helpers/content.rb +28 -7
- data/lib/starlight_helpers/locale.rb +24 -7
- data/lib/starlight_helpers/version.rb +1 -1
- data/starlight_helpers.gemspec +1 -0
- data/test/content_test.rb +31 -6
- data/test/locale_test.rb +20 -6
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45e55034b256a85f964b924fac2efca201e29de7
|
4
|
+
data.tar.gz: 9caccc25808fd94dda3cdb918ddbc0712fc8c08e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69eeea96fbb58530cf4ff315192e36351345fe3ec421369f04c7367242528a2b0498759e963a12f70fed505ee8730e353713e67a8291c3e65f953293a2c6264f
|
7
|
+
data.tar.gz: 8f84b6601c37a506af1f4886a60d328f7ba3c97f37c889c6a9a3825ed6cd9f0af33594f9ea7a11c707d33ea56ad7a01dc8e6c9ab181457229082ba67874bc603
|
data/lib/starlight_helpers.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'redcarpet'
|
2
|
+
require 'redcloth'
|
2
3
|
require 'action_view'
|
3
4
|
|
4
5
|
module StarlightHelpers
|
@@ -11,15 +12,35 @@ module StarlightHelpers
|
|
11
12
|
link_to(name, options, html_options, &block)
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
def render_text(content, markup = 'text/plain', options = {})
|
16
|
+
textile_opts = []
|
17
|
+
markdown_opts = {
|
18
|
+
tables: true, fenced_code_blocks: true, autolink: true,
|
19
|
+
disable_indented_code_blocks: true, strikethrough: true,
|
20
|
+
underline: true, highlight: true, footnotes: true
|
21
|
+
}
|
22
|
+
if options[:not_trusted]
|
23
|
+
textile_opts << :lite_mode << :filter_html
|
24
|
+
markdown_opts = {filter_html: true, no_styles: true}
|
25
|
+
end
|
26
|
+
|
27
|
+
if markup == 'text/markdown'
|
28
|
+
renderer = Redcarpet::Render::HTML.new(markdown_opts)
|
29
|
+
Redcarpet::Markdown.new(renderer).render(content)
|
30
|
+
elsif markup == 'text/textile'
|
31
|
+
RedCloth.new(content, textile_opts).to_html
|
32
|
+
elsif markup == 'text/html' && options[:not_trusted] != true
|
21
33
|
# nothing
|
22
34
|
content
|
35
|
+
# for text/plain and other
|
36
|
+
else
|
37
|
+
content.gsub(/["&'<>]/,
|
38
|
+
'"' => '"',
|
39
|
+
'&' => '&',
|
40
|
+
"'" => ''',
|
41
|
+
'<' => '<',
|
42
|
+
'>' => '>'
|
43
|
+
).gsub("\n", '<br>')
|
23
44
|
end
|
24
45
|
end
|
25
46
|
|
@@ -12,7 +12,7 @@ module StarlightHelpers
|
|
12
12
|
end
|
13
13
|
|
14
14
|
# function parses user agent string from web browser (Accept-Language)
|
15
|
-
# and returns sorted array of {
|
15
|
+
# and returns sorted array of {code => quality} segments
|
16
16
|
def parse_accept_language(ualangs)
|
17
17
|
# quality? format
|
18
18
|
qf = "q=(1|0\.[1-9])"
|
@@ -40,19 +40,36 @@ module StarlightHelpers
|
|
40
40
|
def valid_locale?(loc)
|
41
41
|
loc =~ format ? true : false
|
42
42
|
end
|
43
|
-
|
44
|
-
def language(loc)
|
45
|
-
loc.match(format)[1]
|
46
|
-
end
|
47
43
|
|
48
44
|
def country(loc)
|
49
|
-
loc.match(format)
|
45
|
+
matchdata = loc.match(format)
|
46
|
+
matchdata ? matchdata[3] : nil
|
50
47
|
end
|
51
48
|
|
52
49
|
def country?(loc)
|
53
|
-
loc.match(format)
|
50
|
+
matchdata = loc.match(format)
|
51
|
+
if matchdata
|
52
|
+
matchdata[3] ? true : false
|
53
|
+
else
|
54
|
+
false
|
55
|
+
end
|
54
56
|
end
|
55
57
|
alias_method :full_locale?, :country?
|
58
|
+
|
59
|
+
def language(loc)
|
60
|
+
matchdata = loc.match(format)
|
61
|
+
matchdata ? matchdata[1] : nil
|
62
|
+
end
|
63
|
+
|
64
|
+
def only_language?(loc)
|
65
|
+
matchdata = loc.match(format)
|
66
|
+
if matchdata
|
67
|
+
matchdata[3] ? false : true
|
68
|
+
else
|
69
|
+
false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
alias_method :short_locale?, :only_language?
|
56
73
|
end
|
57
74
|
end
|
58
75
|
|
data/starlight_helpers.gemspec
CHANGED
data/test/content_test.rb
CHANGED
@@ -16,11 +16,36 @@ describe StarlightHelpers::Content do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it '#render_text' do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
assert_equal
|
24
|
-
LesterHelper.
|
19
|
+
text = "h1. *Ahoy*
|
20
|
+
|
21
|
+
<style>body{color: navy}</style>"
|
22
|
+
|
23
|
+
assert_equal "<p>h1. <em>Ahoy</em></p>\n\n<style>body{color: navy}</style>\n",
|
24
|
+
LesterHelper.render_text(text, 'text/markdown')
|
25
|
+
|
26
|
+
assert_equal "<h1><strong>Ahoy</strong></h1>\n<style>body{color: navy}</style>",
|
27
|
+
LesterHelper.render_text(text, 'text/textile')
|
28
|
+
|
29
|
+
assert_equal "h1. *Ahoy*\n\n<style>body{color: navy}</style>",
|
30
|
+
LesterHelper.render_text(text, 'text/html')
|
31
|
+
|
32
|
+
assert_equal "h1. *Ahoy*<br><br><style>body{color: navy}</style>",
|
33
|
+
LesterHelper.render_text(text, 'text/plain')
|
34
|
+
|
35
|
+
# not trusted mode like comments
|
36
|
+
assert_equal "<p>h1. <em>Ahoy</em></p>\n\n<p>body{color: navy}</p>\n",
|
37
|
+
LesterHelper.render_text(text, 'text/markdown', not_trusted: true)
|
38
|
+
|
39
|
+
assert_equal "h1. <strong>Ahoy</strong><br />\n<br />\n<style>body{color: navy}</style>",
|
40
|
+
LesterHelper.render_text(text, 'text/textile', not_trusted: true)
|
41
|
+
|
42
|
+
assert_equal "h1. *Ahoy*<br><br><style>body{color: navy}</style>",
|
43
|
+
LesterHelper.render_text(text, 'text/html', not_trusted: true)
|
44
|
+
|
45
|
+
assert_equal "h1. *Ahoy*<br><br><style>body{color: navy}</style>",
|
46
|
+
LesterHelper.render_text(text, 'text/plain', not_trusted: true)
|
47
|
+
# handled like plain
|
48
|
+
assert_equal "h1. *Ahoy*<br><br><style>body{color: navy}</style>",
|
49
|
+
LesterHelper.render_text(text, 'something', not_trusted: true)
|
25
50
|
end
|
26
51
|
end
|
data/test/locale_test.rb
CHANGED
@@ -16,24 +16,38 @@ describe StarlightHelpers::Locale do
|
|
16
16
|
assert !Lester.valid_locale?('sks_SKs')
|
17
17
|
assert !Lester.valid_locale?('0a_SK')
|
18
18
|
assert !Lester.valid_locale?('0')
|
19
|
-
assert !Lester.valid_locale?('0_SK')
|
19
|
+
assert !Lester.valid_locale?('0_SK')
|
20
|
+
assert !Lester.valid_locale?('sk_')
|
21
|
+
end
|
22
|
+
|
23
|
+
it '#country' do
|
24
|
+
assert_equal 'US', Lester.country('en_US')
|
25
|
+
assert_nil Lester.country('sk')
|
26
|
+
assert_nil Lester.country('invalid')
|
20
27
|
end
|
21
28
|
|
22
29
|
it '#country?, #full_locale?' do
|
23
30
|
assert Lester.country?('sk_SK')
|
24
31
|
assert !Lester.country?('sk')
|
32
|
+
assert !Lester.country?('invalid')
|
25
33
|
assert Lester.full_locale?('sk_SK')
|
26
34
|
assert !Lester.full_locale?('sk')
|
27
|
-
|
28
|
-
|
29
|
-
it '#country' do
|
30
|
-
assert_equal 'US', Lester.country('en_US')
|
31
|
-
assert_nil Lester.country('sk')
|
35
|
+
assert !Lester.full_locale?('invalid')
|
32
36
|
end
|
33
37
|
|
34
38
|
it '#language' do
|
35
39
|
assert_equal 'en', Lester.language('en_US')
|
36
40
|
assert_equal 'sk', Lester.language('sk')
|
41
|
+
assert_nil Lester.language('invalid')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'only_language?' do
|
45
|
+
assert !Lester.only_language?('sk_SK')
|
46
|
+
assert Lester.only_language?('sk')
|
47
|
+
assert !Lester.only_language?('invalid')
|
48
|
+
assert !Lester.short_locale?('sk_SK')
|
49
|
+
assert Lester.short_locale?('sk')
|
50
|
+
assert !Lester.short_locale?('invalid')
|
37
51
|
end
|
38
52
|
|
39
53
|
it '#parse_accept_language' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: starlight_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.1001'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Stana
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: RedCloth
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rack
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
168
|
version: '0'
|
155
169
|
requirements: []
|
156
170
|
rubyforge_project:
|
157
|
-
rubygems_version: 2.2.
|
171
|
+
rubygems_version: 2.2.2
|
158
172
|
signing_key:
|
159
173
|
specification_version: 4
|
160
174
|
summary: Helper modules for building websites. Flash, content, locale and model.
|