shill 0.1.1 → 0.2.0

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
  SHA256:
3
- metadata.gz: 6b37e2e8280c1b400c3d5a9d8faa3a292eadc7835090f01511c1d28658d101d1
4
- data.tar.gz: 8c9584c5fddc36f5aa515119244687771ac4b2cc32aec5be0e4f2318627a8147
3
+ metadata.gz: 4f0ffc8cf45e7690dea17a48ab6370bb9016df49f0e6ca70b701c782316db2ae
4
+ data.tar.gz: 37f21d5c06c84e3f4afd104331476fb17a8f5789cf6c1bfd230678b5b94218e1
5
5
  SHA512:
6
- metadata.gz: 7ebf69a9daf634fc8d66547044274e8cd15df36e14fb5216e4fca278ff32c7b3b0b17bb0f7bb2216fdb11aee1322e16452e3476d5d3864b6604ae6af680e18ea
7
- data.tar.gz: f1d1170b2606988b8bffee707851191bb921a84c52deb723f27fe7e317bd92ef2b30fe1b803557ca1e656975dd51ff1a7b251e993f1492af2b4f9934a25dcc17
6
+ metadata.gz: fa60818f20a34a3080ea6dc83f58a005b546ce59f56a277b245e1f46e6332e284de696e3fe654000b3e8fd0aa3d34ab4401dd3145e0f2a9bb86073a19c8b4329
7
+ data.tar.gz: a2add6060a5e0af99d10faadd0ce372d054c1780b7515620dae1a6bcc66b33b1e17735c0c2dd9e6a81ca321d8ea9e99a29b3fb236e45e0b8414131d3a6b7076c
data/README.md CHANGED
@@ -14,8 +14,7 @@ A tiny, dependency-free Ruby gem that fetches and exposes a list of projects fro
14
14
  Add the gem to your project:
15
15
 
16
16
  ```ruby
17
- gem "shill", github: "marckohlbrugge/shill" # until published on RubyGems
18
- gem "shill" # once published
17
+ gem "shill"
19
18
  ```
20
19
 
21
20
  Then install:
@@ -179,3 +178,27 @@ Shill.projects(refresh: true) # bypasses cache and stores fresh data
179
178
  ```
180
179
 
181
180
  ---
181
+
182
+ ## Rails view helpers
183
+
184
+ Once the gem is loaded in a Rails app, you can access the data directly in any view:
185
+
186
+ ```erb
187
+ <ul>
188
+ <% shill_projects.each do |project| %>
189
+ <li>
190
+ <%= link_to project.name, project.url %> — <%= project.description %>
191
+ </li>
192
+ <% end %>
193
+ </ul>
194
+ ```
195
+
196
+ Need just one?
197
+
198
+ ```erb
199
+ <% if (proj = shill_random_project) %>
200
+ <%= link_to proj.name, proj.url %>
201
+ <% end %>
202
+ ```
203
+
204
+ ---
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shill
4
+ # View-helper methods for Rails
5
+ module Helpers
6
+ # Returns all cached projects (see Shill.projects)
7
+ def shill_projects
8
+ Shill.projects
9
+ end
10
+
11
+ # Returns a single random project
12
+ def shill_random_project
13
+ Shill.random_project
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/railtie"
4
+
5
+ module Shill
6
+ class Railtie < ::Rails::Railtie
7
+ initializer "shill.view_helpers" do
8
+ ActiveSupport.on_load(:action_view) do
9
+ include Shill::Helpers
10
+ end
11
+ end
12
+ end
13
+ end
data/lib/shill/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shill
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/shill.rb CHANGED
@@ -1,6 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "shill/version"
4
+ # Autoload internal files
5
+ require_relative "shill/helpers"
6
+
7
+ # Load Railtie if Rails is present
8
+ if defined?(Rails::Railtie)
9
+ require_relative "shill/railtie"
10
+ end
4
11
 
5
12
  module Shill
6
13
  class Error < StandardError; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Köhlbrugge
@@ -24,6 +24,8 @@ files:
24
24
  - README.md
25
25
  - Rakefile
26
26
  - lib/shill.rb
27
+ - lib/shill/helpers.rb
28
+ - lib/shill/railtie.rb
27
29
  - lib/shill/version.rb
28
30
  - sig/shill.rbs
29
31
  homepage: https://github.com/marckohlbrugge/shill