intercity_express 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c677342e8777d71527e1832f87bcde079b6edbe0
4
+ data.tar.gz: 5cfe770da5ce87b4402794df57a681c1d079c907
5
+ SHA512:
6
+ metadata.gz: 28a4ac4e9af485b5a0bf90e75a861ede678a4f4239dcdcda6f355049fa885b2c47615caf70ae459567293caad59d6da515ba18f3d1f068e4fc653d7426c2fe70
7
+ data.tar.gz: 80db627656d214153aa372cbd923889f83a56c3db2a425d1ee92934486e3bd696dd7dcf91c28f87ad3ff870faaa776929dd1c8aa6352c5594e8636248c69dc59
@@ -0,0 +1,27 @@
1
+ # Intercity Express
2
+
3
+ A collection of helpful utilities for Rails projects. This is a grab bag of things extracted from [Icelab](http://icelab.com.au/) projects.
4
+
5
+ ![ICE](https://cloud.githubusercontent.com/assets/3134/9288909/7b6118c6-43a1-11e5-9e46-6c3c644691d2.jpg "Express to your Gemfile")
6
+
7
+ ## Installation
8
+
9
+ Intercity Express requires Rails 4.2.0 or newer.
10
+
11
+ Add this line to your application’s `Gemfile`:
12
+
13
+ ```ruby
14
+ gem "intercity_express", "~> 1.0.0"
15
+ ```
16
+
17
+ Run `bundle` to install the gem.
18
+
19
+ ## Credits
20
+
21
+ Intercity Express is maintained by [Icelab](http://icelab.com.au/).
22
+
23
+ Cover photo courtesy of [InterCityImpress](https://www.flickr.com/photos/intercityimpress/13758385823).
24
+
25
+ ## License
26
+
27
+ Copyright © 2015 [Icelab](http://icelab.com.au/). Intercity Express is free software, and may be redistributed under the terms specified in the [license](LICENSE.md).
@@ -0,0 +1,10 @@
1
+ require "action_view"
2
+ require "funkify"
3
+ require "redcarpet"
4
+
5
+ require "intercity_express/text_helpers"
6
+ require "intercity_express/railtie" if defined?(Rails::Railtie)
7
+
8
+ # Public: A collection of helpful utilities for Rails projects.
9
+ module IntercityExpress
10
+ end
@@ -0,0 +1,13 @@
1
+ module IntercityExpress
2
+ # Internal: Rails integration for the view helpers.
3
+ #
4
+ # Includes an initializer that automatically adds the view helpers to the
5
+ # set of global helpers.
6
+ class Railtie < Rails::Railtie
7
+ initializer "intercity_express.view_helpers" do
8
+ ActiveSupport.on_load :action_view do
9
+ include IntercityExpress::TextHelpers
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,59 @@
1
+ require "intercity_express/text_helpers/html_without_block_elements_renderer"
2
+
3
+ module IntercityExpress
4
+ # Public: Various helpful text formatting helpers.
5
+ module TextHelpers
6
+ include Funkify
7
+
8
+ def markdown(text)
9
+ (_markdown | _smartypants | _sanitize({}) | _html_safe).(text)
10
+ end
11
+
12
+ def markdown_line(text)
13
+ (_markdown_line | _smartypants | _sanitize({}) | _html_safe).(text)
14
+ end
15
+
16
+ def smartypants_format(text, sanitize_options: {})
17
+ (_smartypants | _sanitize(sanitize_options) | _html_safe).(text)
18
+ end
19
+
20
+ def widont_format(text, sanitize_options: {})
21
+ (_widont | _sanitize(sanitize_options) | _html_safe).(text)
22
+ end
23
+
24
+ private
25
+
26
+ auto_curry
27
+
28
+ def _markdown(text)
29
+ Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(text)
30
+ end
31
+
32
+ def _markdown_line(text)
33
+ renderer = HTMLWithoutBlockElementsRenderer.new(filter_html: false)
34
+ Redcarpet::Markdown.new(renderer, lax_spacing: true, no_intra_emphasis: true).render(text)
35
+ end
36
+
37
+ def _widont(text)
38
+ # Only make the final space non-breaking if the final two words fit
39
+ # within 20 characters.
40
+ if text.length > 20 && text[-20..-1][/\s+\S+\s+\S+$/].nil?
41
+ text
42
+ else
43
+ text.gsub(/\s+(?=\S+$)/, "&nbsp;")
44
+ end
45
+ end
46
+
47
+ def _smartypants(text)
48
+ Redcarpet::Render::SmartyPants.render(text)
49
+ end
50
+
51
+ def _sanitize(options, text)
52
+ sanitize(text, options).strip
53
+ end
54
+
55
+ def _html_safe(text)
56
+ text.html_safe
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,60 @@
1
+ module IntercityExpress
2
+ module TextHelpers
3
+ # Internal: Render any markdown text and ensure it returns only span-level
4
+ # HTML elements.
5
+ #
6
+ # This is intended for use when Markdown styling would be useful for
7
+ # something that must still appear on a single line (like a page title).
8
+ class HTMLWithoutBlockElementsRenderer < Redcarpet::Render::HTML
9
+ def initialize(options = {})
10
+ super(options.merge(tables: false))
11
+ end
12
+
13
+ # Regular markdown, just ignore all the block-level elements
14
+
15
+ def block_code(code, _language)
16
+ " #{code} "
17
+ end
18
+
19
+ def block_quote(quote)
20
+ " #{quote} "
21
+ end
22
+
23
+ def block_html(_raw_html)
24
+ ""
25
+ end
26
+
27
+ def header(text, _header_level)
28
+ " #{text} "
29
+ end
30
+
31
+ def hrule
32
+ " "
33
+ end
34
+
35
+ def list(contents, _list_type)
36
+ contents
37
+ end
38
+
39
+ def list_item(text, _list_type)
40
+ " " + text.strip
41
+ end
42
+
43
+ def paragraph(text)
44
+ text
45
+ end
46
+
47
+ # Span-level calls
48
+
49
+ def linebreak
50
+ " "
51
+ end
52
+
53
+ # Postprocessing: strip newlines
54
+
55
+ def postprocess(document)
56
+ document.tr("\n", " ").strip
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module IntercityExpress #:nodoc:#
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: intercity_express
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Riley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: funkify
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: redcarpet
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.3.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.3.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.33.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.33.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.10.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.10.0
125
+ description: A collection of helpful utilities for Rails projects.
126
+ email:
127
+ - tim@icelab.com.au
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - README.md
133
+ - lib/intercity_express.rb
134
+ - lib/intercity_express/railtie.rb
135
+ - lib/intercity_express/text_helpers.rb
136
+ - lib/intercity_express/text_helpers/html_without_block_elements_renderer.rb
137
+ - lib/intercity_express/version.rb
138
+ homepage: http://github.com/icelab/intercity_express
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.4.5
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: A collection of helpful utilities for Rails projects.
162
+ test_files: []