duffy 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2c0c79fd0c66096e43aabbb8f14e8270a059369
4
- data.tar.gz: 622727f32c423cdbc15f5105f93c7097fc8f7d9c
3
+ metadata.gz: 361bbe6eab3ff805b7cb85505c2eaa7454288060
4
+ data.tar.gz: 3898b205ab16a15c0650c2114ac5ddee28b69d43
5
5
  SHA512:
6
- metadata.gz: 0c347b65e761f2073ac863772a9a6d83c9dd9bab1ee53ff9eb0d56b4fa5cfceb34f56cc89f131c67a4e6a8ce162dd697ee7fe4492aec508536862bd68766fdc8
7
- data.tar.gz: 88ad7895de82a7e4cc6a85d1770822bf466ecac9deff6b81b8be2805867dee410f26458762d1e1dd05a45674b7274f4c5ee13124c17531d06094d2682dc41f31
6
+ metadata.gz: e1dae822379c3e5093f64b02918624bce7fb1dea26bc8879f3904c78c2e5b7924103fa1413b8dbbfcd76bbf100aa5d177360a81025825812272b52fff92da226
7
+ data.tar.gz: c15affda9804b108a6de7e1236b8c774a8e91a4f4f435d5f19f7a150eeb350d4535a0b506813c4c20312cd3ac0e57a670f6642f6fac6b0220e1ab13f7f659175
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # Duffy
2
2
 
3
- TODO: Write a gem description
3
+ This is a collection of reusable things I don't want to keep duplicating in tons of projects.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
+ * This is a work in progress. If someone decides to use this, you may want to lock your version number in your gemfile.
8
9
 
9
10
  ```ruby
10
11
  gem 'duffy'
@@ -14,13 +15,36 @@ And then execute:
14
15
 
15
16
  $ bundle
16
17
 
17
- Or install it yourself as:
18
+ ## Usage
18
19
 
19
- $ gem install duffy
20
+ String Patches:
21
+ ```ruby
22
+ to_ssn
23
+ to_numeric
24
+ to_alpha
25
+ to_alpha_numeric
26
+ pretty_phone
27
+ pretty_committer # TODO: Setup gem configuration to load patterns
28
+ space2nbsp
29
+ nl2br
30
+ gender_human
31
+ smart_titlecase # Note: Has config options. See lib/duffy.rb
32
+ ```
20
33
 
21
- ## Usage
34
+ Git Access:
35
+ This one is namespaced incase you use the 'git' gem. I found it to be overkill for what I wanted.
36
+ ```ruby
37
+ Duffy::Git.log # => Produce tab separated listing of current git log.
38
+ Duffy::Git.count # => Count of git commits in current branch
39
+ ```
22
40
 
23
- TODO: Write usage instructions here
41
+ View Helpers:
42
+ This is a work in progress. I'm going to try to put all my generic helpers here.
43
+ ```ruby
44
+ menu_tag
45
+ excel_icon
46
+ icon
47
+ ```
24
48
 
25
49
  ## Contributing
26
50
 
@@ -1,32 +1,38 @@
1
1
  module DuffyHelper
2
2
 
3
- def menu_tag( title, link, options = {})
4
- link_to(content_tag(:li, title, options), link)
3
+ # This creates menu entries in the format Zurb Foundation expects.
4
+ # It's just an <li> with a link inside it.
5
+ # menu_tag('Help', help_path) => <li><a href="/help">Help</a></li>
6
+ def menu_tag(title, link, options = {})
7
+ content_tag(:li, link_to(title, link), options)
5
8
  end
6
9
 
7
- def excel_icon(link = params.merge(:format => "xlsx"))
8
- # Create Excel icon in consistent location
10
+ # Create Excel icon in consistent location
11
+ # This is intended to display the xlsx version of a view.
12
+ # Add a yield(:excel) somewhere in your application layout:
13
+ # content_tag( :li, yield(:excel), class: :excel) if content_for?(:excel)
14
+ def excel_icon(link = params.merge(format: "xlsx"))
9
15
  content_for :excel do
10
- link_to(image_tag('excel.png', :width => 40, :height => 40), link)
16
+ link_to(image_tag('excel.png'), link)
11
17
  end
12
18
  end
13
19
 
20
+ # Create a simple link with the class "icon"
21
+ # Generate a uniq and reasonable id based on the link passed (if any)
22
+ # Add any classes passed in via options
23
+ # Add the "favorite" class if icon is favorited
24
+ # - This is application specific and will just not do anything if it runs into a problem
25
+ # If any uncaught exceptions are thrown in production you'll just get nothing, otherwise you'll get the error on screen.
14
26
  def icon(title, link, options = {})
15
27
  begin
16
- options[:id] = "icon_#{link.parameterize("_")}"
28
+ options[:id] = "icon_#{link.parameterize("_")}" unless link.blank?
17
29
  options[:class] = [:icon] << options[:class]
18
- options[:class] << "favorite" if defined?(current_user) and (current_user.person.details.where(key: "favorite_#{options[:id]}").any? rescue false)
30
+ options[:class] << :favorite if defined?(current_user) and (current_user.person.details.where(key: "favorite_#{options[:id]}").any? rescue false)
31
+ options[:class] = options[:class].flatten.compact
19
32
  link_to(title, link, options)
20
33
  rescue Exception => e
21
34
  Rails.env.development? ? content_tag(:p, e) : nil
22
35
  end
23
36
  end
24
37
 
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
38
  end
data/lib/duffy/string.rb CHANGED
@@ -57,14 +57,10 @@ class String
57
57
  end
58
58
 
59
59
  # Parse a git username into a friendly name
60
+ # Expects committers to be a hash in this format: { jpd" => "Jacob", /ers|Eric/ => "Eric" }
61
+ # All String keys are converted to Regex, explicit Regex is fine too.
60
62
  def pretty_committer
61
- case self
62
- when /jpd/ then "Jacob"
63
- when /ers|Eric/ then "Eric"
64
- when /gac/ then "Glenn"
65
- when /jes/ then "Samsky"
66
- else self
67
- end
63
+ Hash(Duffy.configuration.committers).map{|k,v| v if Regexp.new(k) =~ self}.compact.first or self
68
64
  end
69
65
 
70
66
  def space2nbsp
@@ -125,9 +121,11 @@ class String
125
121
  end #each
126
122
 
127
123
  # Special Cases:
124
+ upcase_re = (Array(Duffy.configuration.upcase_custom) + Array(Duffy.configuration.upcase_default)).uniq.join("|")
125
+
128
126
  result.gsub!(/ V(s?)\. /, ' v\1. ') # "v." and "vs."
129
127
  result.gsub!(/([''])S\b/, '\1s') # 'S (otherwise you get "the SEC'S decision")
130
- result.gsub!(/\b(AOB|AT&T|Q&A|II|III|IV|HR|CT|CHS|CME|DFM|HRS|PA|UDDS|USA|UWMF|WREN)\b/i) { |w| w.upcase } # "AT&T" and "Q&A", which get tripped up by
128
+ result.gsub!(/\b(#{upcase_re})\b/i) { |w| w.upcase } unless upcase_re.blank?
131
129
  result
132
130
  end
133
131
  end
data/lib/duffy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Duffy
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/duffy.rb CHANGED
@@ -13,4 +13,38 @@ require File.dirname(__FILE__) + "/duffy/railtie" if defined?(Rails)
13
13
  module Duffy
14
14
  class Engine < Rails::Engine
15
15
  end
16
- end
16
+
17
+ def self.configuration
18
+ @configuration ||= Duffy::Configuration.new
19
+ end
20
+
21
+ def self.configure
22
+ yield configuration
23
+ end
24
+
25
+ # Override any duffy defaults conveniently with config options
26
+ # example:
27
+ # [config/initializers/duffy.rb]
28
+ # Duffy.configure do |config|
29
+ # config.upcase_custom = %w(AOB CHS CME CT DFM HRS PA UDDS UWMF WREN)
30
+ # end
31
+ #
32
+ class Configuration
33
+ include ActiveSupport::Configurable
34
+
35
+ # Smart Titlecase
36
+ # Use :update_custom to add uppercase special cases
37
+ # Use :update_default to replace my defaults
38
+ config_accessor(:upcase_custom) # {%w(NBC CNN FOO)}
39
+ config_accessor(:upcase_default) {%w(HR II III IV Q&A USA)}
40
+
41
+ # Pretty Committer
42
+ config_accessor(:committers) # {"jpd" => "Jacob", "ers|Eric" => "Eric"}
43
+
44
+ end
45
+
46
+
47
+ end
48
+
49
+
50
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duffy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Duffy
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  version: '0'
97
97
  requirements: []
98
98
  rubyforge_project:
99
- rubygems_version: 2.4.2
99
+ rubygems_version: 2.4.3
100
100
  signing_key:
101
101
  specification_version: 4
102
102
  summary: Library of things