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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a3b4b798441b86215b526db3c2cc0a856a89ed9
4
- data.tar.gz: a723db3edfb4bc5b3305115df2fa3c8f2b23e880
3
+ metadata.gz: 45e55034b256a85f964b924fac2efca201e29de7
4
+ data.tar.gz: 9caccc25808fd94dda3cdb918ddbc0712fc8c08e
5
5
  SHA512:
6
- metadata.gz: 1564ea9d08e5f9fe0e4f45843ed433a38465b0876f634958eb56574e56c900a34fbd6bb453f2bee89188d12af57b5eaac6c927d2c3739a1eea41fded95fd3e29
7
- data.tar.gz: 006d29a60f780a0dc05023bca2875c89d9f726f8dc4cb4a5bc778d26058748d1e418cc9c1ac39ea9aff09f8e1e10a0207d210618dd881cb8388218c59a23aed2
6
+ metadata.gz: 69eeea96fbb58530cf4ff315192e36351345fe3ec421369f04c7367242528a2b0498759e963a12f70fed505ee8730e353713e67a8291c3e65f953293a2c6264f
7
+ data.tar.gz: 8f84b6601c37a506af1f4886a60d328f7ba3c97f37c889c6a9a3825ed6cd9f0af33594f9ea7a11c707d33ea56ad7a01dc8e6c9ab181457229082ba67874bc603
@@ -1,4 +1,5 @@
1
1
  require "starlight_helpers/version"
2
2
 
3
3
  module StarlightHelpers
4
+ require "starlight_helpers/all"
4
5
  end
@@ -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 convert_content(content, markup)
15
- if markup == 'plain'
16
- content.gsub("\n", '<br>')
17
- elsif markup == 'markdown'
18
- markdown = ::Redcarpet::Markdown.new(::Redcarpet::Render::HTML)
19
- markdown.render(content)
20
- elsif markup == 'html'
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
+ '"' => '&quot;',
39
+ '&' => '&amp;',
40
+ "'" => '&apos;',
41
+ '<' => '&lt;',
42
+ '>' => '&gt;'
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 {quality => code} segments
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)[3]
45
+ matchdata = loc.match(format)
46
+ matchdata ? matchdata[3] : nil
50
47
  end
51
48
 
52
49
  def country?(loc)
53
- loc.match(format)[3] != nil
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
 
@@ -1,3 +1,3 @@
1
1
  module StarlightHelpers
2
- VERSION = "0.1000"
2
+ VERSION = "0.1001"
3
3
  end
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency "actionpack"
23
23
  spec.add_dependency "redcarpet"
24
+ spec.add_dependency "RedCloth"
24
25
  spec.add_dependency "rack"
25
26
  spec.add_dependency "actionview"
26
27
 
@@ -16,11 +16,36 @@ describe StarlightHelpers::Content do
16
16
  end
17
17
 
18
18
  it '#render_text' do
19
- assert_equal 'Hello<br>world',
20
- LesterHelper.convert_content("Hello\nworld", 'plain')
21
- assert_equal "<p><em>Hello</em></p>\n",
22
- LesterHelper.convert_content("*Hello*", 'markdown')
23
- assert_equal '<font color="navy">Hello</font>',
24
- LesterHelper.convert_content('<font color="navy">Hello</font>', 'html')
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>&lt;style&gt;body{color: navy}&lt;/style&gt;",
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&lt;style&gt;body{color: navy}&lt;/style&gt;",
40
+ LesterHelper.render_text(text, 'text/textile', not_trusted: true)
41
+
42
+ assert_equal "h1. *Ahoy*<br><br>&lt;style&gt;body{color: navy}&lt;/style&gt;",
43
+ LesterHelper.render_text(text, 'text/html', not_trusted: true)
44
+
45
+ assert_equal "h1. *Ahoy*<br><br>&lt;style&gt;body{color: navy}&lt;/style&gt;",
46
+ LesterHelper.render_text(text, 'text/plain', not_trusted: true)
47
+ # handled like plain
48
+ assert_equal "h1. *Ahoy*<br><br>&lt;style&gt;body{color: navy}&lt;/style&gt;",
49
+ LesterHelper.render_text(text, 'something', not_trusted: true)
25
50
  end
26
51
  end
@@ -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
- end
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.1000'
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-02-14 00:00:00.000000000 Z
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.0
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.