wrap_guard 0.0.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cc3d497ef02af0bb6f918f8ace31bbe76474b52651b901a80597fa9d6b17bc95
4
+ data.tar.gz: c55a200ba5cade2ad591708675259ec484df755d29ed2905834dcc8198c060c6
5
+ SHA512:
6
+ metadata.gz: caa1b5d9c458ee2f44d5924a2084ff71123461bd4deb4efe2a42f3465b38150e3ce74a6af8a8ffb39ea9cfd995c517af5c1786927bc3d5307aa5712fca9575af
7
+ data.tar.gz: 7e5e7158f193673ee9b9bcdd499e3b060e9aa435591a6b203a634cb81ea22a25796f83a1518de03946d3d50b690b8f379d89d0dff4b101ec6234380c51da0ba4
data/lib/wrap_guard.rb ADDED
@@ -0,0 +1 @@
1
+ require 'wrap_guard/railtie' if defined?(Rails)
@@ -0,0 +1,7 @@
1
+ require 'wrap_guard/view_helpers'
2
+
3
+ module WrapGuard
4
+ class Railtie < Rails::Railtie
5
+ ActiveSupport.on_load( :action_view ){ include WrapGuard::ViewHelpers }
6
+ end
7
+ end
@@ -0,0 +1,44 @@
1
+ module WrapGuard
2
+ class Configuration
3
+ attr_accessor :wrap_open, :wrap_close
4
+
5
+ def initialize
6
+ @wrap_open = "<span class='wg-no-wrap'>"
7
+ @wrap_close = "</span>"
8
+ end
9
+ end
10
+
11
+ class << self
12
+ def configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ def configure
17
+ yield configuration
18
+ end
19
+ end
20
+
21
+ module ViewHelpers
22
+
23
+ def self.wrap_guard(str, words: 2)
24
+ index_to_insert_span = last_space(str, words) + 1
25
+ str.insert(index_to_insert_span, WrapGuard.configuration.wrap_open) + WrapGuard.configuration.wrap_close
26
+ end
27
+
28
+ class << self
29
+ alias :wg :wrap_guard
30
+ end
31
+
32
+ private
33
+
34
+ def self.last_space(str, words)
35
+ if words == 0
36
+ str.length
37
+ else
38
+ last_space_index = str.rindex(' ')
39
+ last_space str[0, last_space_index], words - 1
40
+ end
41
+ end
42
+
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wrap_guard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Ethan Dowler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Never deal with orphan words again! https://github.com/ethan-dowler/wrap_guard
14
+ email: tedowler@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/wrap_guard.rb
20
+ - lib/wrap_guard/railtie.rb
21
+ - lib/wrap_guard/view_helpers.rb
22
+ homepage: https://rubygems.org/gems/wrap_guard
23
+ licenses: []
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.7.3
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Prevent orphaned words in your web app.
45
+ test_files: []