duffy 0.2.4 → 0.2.5

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: d01359db9f3ec823f91ff534d3870712e0bcc599
4
- data.tar.gz: c7b30c4d7e0ae05db21a0eaa335e3765c3d349f7
3
+ metadata.gz: 304f86f07f2a4318944a13f241921faba0d8f969
4
+ data.tar.gz: d90859be246a584b6cd460c8a8d942a1de39c07d
5
5
  SHA512:
6
- metadata.gz: 51b4dee46a3905df6e1681a6724141842f258a14bbd3fe9e303d69f743c55680a9f855bfca5f12869bb81d9fdd75b16826a04b3a1cabf008118924cfc19e5375
7
- data.tar.gz: 954f4d3b21b9b4a73e7c73b02c5cbde845988046486aaa21a5b721e552ff754f0ca3a89adc33f3c25aa50858c114e1df45487717f128f12cdbf03e6a8da1cea4
6
+ metadata.gz: 6ff94dbc71c7d44f306a1698173ac7a05763a16b3c44d0090b182561d57eb565edd935431b36a70deec574743a7c1fa92054ac1cd59208607f4f37819366c565
7
+ data.tar.gz: 66637e5c757d8e36a12911abb8395215d3d7119118fb6e703a6871c7c7bc1bc36761c088218813a831988bc2b629023d73c20fd36e58c112825009a264e6355e
data/README.md CHANGED
@@ -8,7 +8,6 @@ This is a collection of reusable things I don't want to keep duplicating in tons
8
8
  ## Installation
9
9
 
10
10
  Add this line to your application's Gemfile:
11
- * This is a work in progress. If someone decides to use this, you may want to lock your version number in your gemfile.
12
11
 
13
12
  ```ruby
14
13
  gem 'duffy'
@@ -39,21 +38,21 @@ gender_human | "F" | "Female"
39
38
  smart_titlecase | "this and that" | "This and That" (Note: Has config options. See lib/duffy.rb)
40
39
 
41
40
 
42
- Date Patches:
41
+ ## Date Patches:
43
42
 
44
43
  Method | Example | Output
45
44
  ------------------|-----------------|-------
46
45
  fiscal_year | Date.today | 2015 (See config to set your organization's fiscal year start.)
47
46
 
48
47
 
49
- NilClass Patches:
48
+ ## NilClass Patches:
50
49
 
51
50
  Method | Example | Output
52
51
  ------------------|-----------------|-------
53
52
  to_date | nil | self (Exists so you can call .to_date on Date, String or nil
54
53
 
55
54
 
56
- Active Record Aliases:
55
+ ## Active Record Aliases:
57
56
 
58
57
  Alias | Standard
59
58
  ------------------|---------
@@ -61,35 +60,41 @@ accepts | accepts_nested_attributes_for
61
60
  habtm | has_and_belongs_to_many
62
61
 
63
62
 
64
- Git Access:
63
+ ## Git Access:
65
64
  This one is namespaced in case you use the 'git' gem. I found it to be overkill for what I wanted.
66
- ```ruby
67
- Duffy::Git.log # => Produce tab separated listing of current git log.
68
- Duffy::Git.count # => Count of git commits in current branch
69
- Duffy::Git.email # => Local repo's git user.email or global if none.
70
- Duffy::Git.branch # => Current git branch.
71
- ```
72
65
 
73
- CPU Detection:
66
+ Method | Result
67
+ ----------|---------
68
+ Duffy::Git.log | Produce tab separated listing of current git log.
69
+ Duffy::Git.count | Count of git commits in current branch
70
+ Duffy::Git.email | Local repo's git user.email or global if none.
71
+ Duffy::Git.branch | Current git branch.
72
+
73
+
74
+ ## CPU Detection:
74
75
  Linux and Mac only for now, each method returns 1 on unsupported hosts.
75
76
  Example results for my dual core i5 with hyperthreading.
76
- ```ruby
77
- Duffy::System.cpus # => 1
78
- Duffy::System.cores # => 2
79
- Duffy::System.threads # => 4
80
- Duffy::System.sane_load # => 3
81
- ```
82
77
 
78
+ Method | Result
79
+ ----------|---------
80
+ Duffy::System.cpus | 1
81
+ Duffy::System.cores | 2
82
+ Duffy::System.threads | 4
83
+ Duffy::System.sane_load | 3
84
+
85
+
86
+
87
+ ## View Helpers:
88
+
89
+ Method | Example | Result
90
+ ------------|-------------------------------------|-------
91
+ beast_mode | beast_mode tags | renders tag partial in parallel. Only available if you have the Parallel gem in your Gemfile. You must also wrap your partial in a cache block.
92
+ excel_icon | excel_icon | generates hyperlinked excel.png in an li block to .xlsx version of current page or passed link. Maintains current GET params.
93
+ icon | icon("tags", tags_path) | generates link of class "icon" with the title and link provided. also sets id based on controller and action |
94
+ menu_tag | menu_tag("Login", login_path) | generated hyperlinked li block used in common ul based navigation toolbars.
83
95
 
84
- View Helpers:
85
- This is a work in progress. I'm going to try to put all my generic helpers here.
86
- ```ruby
87
- menu_tag
88
- excel_icon
89
- icon
90
- ```
91
96
 
92
- CSS Reset & Print Styles: Very barebones CSS Reset / Sensible defaults and Print stylesheets.
97
+ ## CSS Reset & Print Styles: Very barebones CSS Reset / Sensible defaults and Print stylesheets.
93
98
  ```ruby
94
99
  require duffy/reset
95
100
  require duffy/print
@@ -0,0 +1,49 @@
1
+ module BeastModeHelper
2
+
3
+ # Cache each partial in a collection, then display from cache.
4
+ #
5
+ # IMPORTANT: This only works if you've wrapped your partial in a cache block.
6
+ # If you don't it will take longer than just calling render()
7
+ # You also need the Parallel gem installed: https://github.com/grosser/parallel
8
+ #
9
+ # Examples:
10
+ # beast_mode(@jobs)
11
+ # beast_mode(partial: 'jobs/job', collection: @jobs)
12
+ #
13
+ def beast_mode(options = {})
14
+
15
+ if defined? Parallel
16
+
17
+ if options.is_a?(Hash)
18
+ # eg: beast_mode(partial: 'jobs/job', collection: @jobs)
19
+
20
+ # Issue ArgumentError if anything is missing
21
+ raise ArgumentError.new("partial: option is required") unless options.has_key?(:partial)
22
+ raise ArgumentError.new("collection: option is required") unless options.has_key?(:collection)
23
+
24
+ collection = options[:collection]
25
+ partial = options[:partial]
26
+
27
+ # Issue ArgumentError if collection isn't a collection
28
+ raise ArgumentError.new("collection doesn't look like something I can render") unless collection.respond_to?(:each)
29
+
30
+
31
+ # silently render each partial as quickly as possible. It's up to you to include a cache block!
32
+ Parallel.each(collection, in_processes: MAX_PROCESSES) do |object|
33
+ render(partial: partial, object: object)
34
+ end
35
+ else
36
+ # eg: beast_mode(@jobs)
37
+ # Generate the Cache fragments for each object in parallel as fast as possible, but don't show them yet
38
+ Parallel.each(options, in_processes: MAX_PROCESSES) do |object|
39
+ render(object)
40
+ end
41
+ end
42
+ else
43
+ warn " [WARNING] beast_mode is not executing in parallel. Please add https://github.com/grosser/parallel"
44
+ end
45
+
46
+ # Display the cached fragments.
47
+ render(options)
48
+ end
49
+ end
data/lib/duffy/railtie.rb CHANGED
@@ -1,10 +1,16 @@
1
1
  # http://stackoverflow.com/questions/5791211/how-do-i-extract-rails-view-helpers-into-a-gem
2
2
 
3
3
  require File.dirname(__FILE__) + "/duffy_helper"
4
+ require File.dirname(__FILE__) + "/beast_mode_helper"
5
+
4
6
  module Duffy
5
7
  class Railtie < Rails::Railtie
6
8
  initializer "duffy_helper" do
7
9
  ActiveSupport.on_load( :action_view ){ include DuffyHelper }
8
10
  end
11
+
12
+ initializer "beast_mode_helper" do
13
+ ActiveSupport.on_load( :action_view ){ include BeastModeHelper }
14
+ end
9
15
  end
10
16
  end
data/lib/duffy/version.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module Duffy
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
4
4
 
5
5
  # History
6
+ # 0.2.5 - Added beast_mode helper to render partials in parallel
6
7
  # 0.2.4 - Added NilClass.to_date => nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duffy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Duffy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-21 00:00:00.000000000 Z
11
+ date: 2016-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -96,6 +96,7 @@ files:
96
96
  - duffy.gemspec
97
97
  - lib/duffy.rb
98
98
  - lib/duffy/active_record.rb
99
+ - lib/duffy/beast_mode_helper.rb
99
100
  - lib/duffy/date.rb
100
101
  - lib/duffy/duffy_helper.rb
101
102
  - lib/duffy/engine.rb