├── .github
├── FUNDING.yml
├── dependabot.yml
└── workflows
│ ├── depsreview.yml
│ └── main.yml
├── .gitignore
├── .rubocop.yml
├── .standard.yml
├── Gemfile
├── Gemfile.lock
├── MIT-LICENSE
├── README.md
├── Rakefile
├── bin
├── test
└── unsplash_image
├── lib
├── tasks
│ └── unsplash_image_tasks.rake
├── unsplash_image.rb
└── unsplash_image
│ ├── cli.rb
│ ├── download.rb
│ ├── helper.rb
│ ├── railtie.rb
│ └── version.rb
├── test
├── dummy
│ ├── Rakefile
│ ├── app
│ │ ├── assets
│ │ │ ├── images
│ │ │ │ └── .keep
│ │ │ └── stylesheets
│ │ │ │ └── application.css
│ │ ├── channels
│ │ │ └── application_cable
│ │ │ │ ├── channel.rb
│ │ │ │ └── connection.rb
│ │ ├── controllers
│ │ │ ├── application_controller.rb
│ │ │ ├── concerns
│ │ │ │ └── .keep
│ │ │ └── home_controller.rb
│ │ ├── helpers
│ │ │ └── application_helper.rb
│ │ ├── jobs
│ │ │ └── application_job.rb
│ │ ├── mailers
│ │ │ └── application_mailer.rb
│ │ ├── models
│ │ │ ├── application_record.rb
│ │ │ └── concerns
│ │ │ │ └── .keep
│ │ └── views
│ │ │ ├── home
│ │ │ └── index.html.erb
│ │ │ └── layouts
│ │ │ ├── application.html.erb
│ │ │ ├── mailer.html.erb
│ │ │ └── mailer.text.erb
│ ├── bin
│ │ ├── rails
│ │ ├── rake
│ │ └── setup
│ ├── config.ru
│ ├── config
│ │ ├── application.rb
│ │ ├── boot.rb
│ │ ├── cable.yml
│ │ ├── database.yml
│ │ ├── environment.rb
│ │ ├── environments
│ │ │ ├── development.rb
│ │ │ ├── production.rb
│ │ │ └── test.rb
│ │ ├── initializers
│ │ │ ├── content_security_policy.rb
│ │ │ ├── filter_parameter_logging.rb
│ │ │ ├── inflections.rb
│ │ │ └── permissions_policy.rb
│ │ ├── locales
│ │ │ └── en.yml
│ │ ├── puma.rb
│ │ ├── routes.rb
│ │ └── storage.yml
│ ├── lib
│ │ └── assets
│ │ │ └── .keep
│ ├── log
│ │ └── .keep
│ └── public
│ │ ├── 404.html
│ │ ├── 422.html
│ │ ├── 500.html
│ │ ├── apple-touch-icon-precomposed.png
│ │ ├── apple-touch-icon.png
│ │ └── favicon.ico
├── test_helper.rb
└── unsplash_image_test.rb
└── unsplash_image.gemspec
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | patreon: igorkasyanchuk
2 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # To get started with Dependabot version updates, you'll need to specify which
2 | # package ecosystems to update and where the package manifests are located.
3 | # Please see the documentation for all configuration options:
4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5 |
6 | version: 2
7 | updates:
8 | - package-ecosystem: "bundler"
9 | directory: "/"
10 | schedule:
11 | interval: "daily"
12 |
--------------------------------------------------------------------------------
/.github/workflows/depsreview.yml:
--------------------------------------------------------------------------------
1 | name: 'Dependency Review'
2 |
3 | on: [pull_request]
4 |
5 | permissions:
6 | contents: read
7 |
8 | jobs:
9 | dependency-review:
10 | runs-on: ubuntu-latest
11 | steps:
12 | - name: 'Checkout Repository'
13 | uses: actions/checkout@v3
14 | - name: 'Dependency Review'
15 | uses: actions/dependency-review-action@v1
16 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | branches: [ main ]
6 | pull_request:
7 | branches: [ main ]
8 |
9 | permissions:
10 | contents: read
11 |
12 | jobs:
13 | standardrb:
14 | runs-on: ubuntu-latest
15 |
16 | steps:
17 | - uses: actions/checkout@v3
18 | - name: Set up Ruby
19 | uses: ruby/setup-ruby@v1
20 | with:
21 | bundler-cache: true
22 | ruby-version: "2.7"
23 | - name: Run standardrb
24 | run: bundle exec standardrb
25 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.bundle/
2 | /doc/
3 | /log/*.log
4 | /pkg/
5 | /tmp/
6 | /test/dummy/db/*.sqlite3
7 | /test/dummy/db/*.sqlite3-*
8 | /test/dummy/log/*.log
9 | /test/dummy/storage/
10 | /test/dummy/tmp/
11 |
12 | *.gem
13 |
--------------------------------------------------------------------------------
/.rubocop.yml:
--------------------------------------------------------------------------------
1 | require: standard
2 |
3 | inherit_gem:
4 | standard: config/base.yml
5 |
6 | Layout/ExtraSpacing:
7 | Enabled: false
8 |
--------------------------------------------------------------------------------
/.standard.yml:
--------------------------------------------------------------------------------
1 | ignore:
2 | - '**/**':
3 | - Layout/ExtraSpacing
4 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source "https://rubygems.org"
2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3 |
4 | # Specify your gem's dependencies in unsplash_image.gemspec.
5 | gemspec
6 |
7 | gem "sqlite3"
8 |
9 | gem "standard", group: [:development, :test]
10 |
11 | # Start debugger with binding.b [https://github.com/ruby/debug]
12 | # gem "debug", ">= 1.0.0"
13 |
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | PATH
2 | remote: .
3 | specs:
4 | unsplash_image (0.1.1)
5 | thor (>= 0.20)
6 |
7 | GEM
8 | remote: https://rubygems.org/
9 | specs:
10 | actioncable (7.0.3.1)
11 | actionpack (= 7.0.3.1)
12 | activesupport (= 7.0.3.1)
13 | nio4r (~> 2.0)
14 | websocket-driver (>= 0.6.1)
15 | actionmailbox (7.0.3.1)
16 | actionpack (= 7.0.3.1)
17 | activejob (= 7.0.3.1)
18 | activerecord (= 7.0.3.1)
19 | activestorage (= 7.0.3.1)
20 | activesupport (= 7.0.3.1)
21 | mail (>= 2.7.1)
22 | net-imap
23 | net-pop
24 | net-smtp
25 | actionmailer (7.0.3.1)
26 | actionpack (= 7.0.3.1)
27 | actionview (= 7.0.3.1)
28 | activejob (= 7.0.3.1)
29 | activesupport (= 7.0.3.1)
30 | mail (~> 2.5, >= 2.5.4)
31 | net-imap
32 | net-pop
33 | net-smtp
34 | rails-dom-testing (~> 2.0)
35 | actionpack (7.0.3.1)
36 | actionview (= 7.0.3.1)
37 | activesupport (= 7.0.3.1)
38 | rack (~> 2.0, >= 2.2.0)
39 | rack-test (>= 0.6.3)
40 | rails-dom-testing (~> 2.0)
41 | rails-html-sanitizer (~> 1.0, >= 1.2.0)
42 | actiontext (7.0.3.1)
43 | actionpack (= 7.0.3.1)
44 | activerecord (= 7.0.3.1)
45 | activestorage (= 7.0.3.1)
46 | activesupport (= 7.0.3.1)
47 | globalid (>= 0.6.0)
48 | nokogiri (>= 1.8.5)
49 | actionview (7.0.3.1)
50 | activesupport (= 7.0.3.1)
51 | builder (~> 3.1)
52 | erubi (~> 1.4)
53 | rails-dom-testing (~> 2.0)
54 | rails-html-sanitizer (~> 1.1, >= 1.2.0)
55 | activejob (7.0.3.1)
56 | activesupport (= 7.0.3.1)
57 | globalid (>= 0.3.6)
58 | activemodel (7.0.3.1)
59 | activesupport (= 7.0.3.1)
60 | activerecord (7.0.3.1)
61 | activemodel (= 7.0.3.1)
62 | activesupport (= 7.0.3.1)
63 | activestorage (7.0.3.1)
64 | actionpack (= 7.0.3.1)
65 | activejob (= 7.0.3.1)
66 | activerecord (= 7.0.3.1)
67 | activesupport (= 7.0.3.1)
68 | marcel (~> 1.0)
69 | mini_mime (>= 1.1.0)
70 | activesupport (7.0.3.1)
71 | concurrent-ruby (~> 1.0, >= 1.0.2)
72 | i18n (>= 1.6, < 2)
73 | minitest (>= 5.1)
74 | tzinfo (~> 2.0)
75 | ast (2.4.2)
76 | builder (3.2.4)
77 | coderay (1.1.3)
78 | concurrent-ruby (1.1.10)
79 | crass (1.0.6)
80 | digest (3.1.0)
81 | erubi (1.10.0)
82 | faker (2.22.0)
83 | i18n (>= 1.8.11, < 2)
84 | globalid (1.0.0)
85 | activesupport (>= 5.0)
86 | i18n (1.12.0)
87 | concurrent-ruby (~> 1.0)
88 | json (2.6.2)
89 | loofah (2.18.0)
90 | crass (~> 1.0.2)
91 | nokogiri (>= 1.5.9)
92 | mail (2.7.1)
93 | mini_mime (>= 0.1.1)
94 | marcel (1.0.2)
95 | method_source (1.0.0)
96 | mini_mime (1.1.2)
97 | minitest (5.16.2)
98 | net-imap (0.2.3)
99 | digest
100 | net-protocol
101 | strscan
102 | net-pop (0.1.1)
103 | digest
104 | net-protocol
105 | timeout
106 | net-protocol (0.1.3)
107 | timeout
108 | net-smtp (0.3.1)
109 | digest
110 | net-protocol
111 | timeout
112 | nio4r (2.5.8)
113 | nokogiri (1.13.7-arm64-darwin)
114 | racc (~> 1.4)
115 | nokogiri (1.13.7-x86_64-darwin)
116 | racc (~> 1.4)
117 | nokogiri (1.13.7-x86_64-linux)
118 | racc (~> 1.4)
119 | parallel (1.22.1)
120 | parser (3.1.2.1)
121 | ast (~> 2.4.1)
122 | pry (0.14.1)
123 | coderay (~> 1.1)
124 | method_source (~> 1.0)
125 | puma (5.6.5)
126 | nio4r (~> 2.0)
127 | racc (1.6.0)
128 | rack (2.2.4)
129 | rack-test (2.0.2)
130 | rack (>= 1.3)
131 | rails (7.0.3.1)
132 | actioncable (= 7.0.3.1)
133 | actionmailbox (= 7.0.3.1)
134 | actionmailer (= 7.0.3.1)
135 | actionpack (= 7.0.3.1)
136 | actiontext (= 7.0.3.1)
137 | actionview (= 7.0.3.1)
138 | activejob (= 7.0.3.1)
139 | activemodel (= 7.0.3.1)
140 | activerecord (= 7.0.3.1)
141 | activestorage (= 7.0.3.1)
142 | activesupport (= 7.0.3.1)
143 | bundler (>= 1.15.0)
144 | railties (= 7.0.3.1)
145 | rails-dom-testing (2.0.3)
146 | activesupport (>= 4.2.0)
147 | nokogiri (>= 1.6)
148 | rails-html-sanitizer (1.4.3)
149 | loofah (~> 2.3)
150 | railties (7.0.3.1)
151 | actionpack (= 7.0.3.1)
152 | activesupport (= 7.0.3.1)
153 | method_source
154 | rake (>= 12.2)
155 | thor (~> 1.0)
156 | zeitwerk (~> 2.5)
157 | rainbow (3.1.1)
158 | rake (13.0.6)
159 | regexp_parser (2.5.0)
160 | rexml (3.2.5)
161 | rubocop (1.33.0)
162 | json (~> 2.3)
163 | parallel (~> 1.10)
164 | parser (>= 3.1.0.0)
165 | rainbow (>= 2.2.2, < 4.0)
166 | regexp_parser (>= 1.8, < 3.0)
167 | rexml (>= 3.2.5, < 4.0)
168 | rubocop-ast (>= 1.19.1, < 2.0)
169 | ruby-progressbar (~> 1.7)
170 | unicode-display_width (>= 1.4.0, < 3.0)
171 | rubocop-ast (1.21.0)
172 | parser (>= 3.1.1.0)
173 | rubocop-performance (1.14.3)
174 | rubocop (>= 1.7.0, < 2.0)
175 | rubocop-ast (>= 0.4.0)
176 | ruby-progressbar (1.11.0)
177 | sqlite3 (1.4.4)
178 | standard (1.15.0)
179 | rubocop (= 1.33.0)
180 | rubocop-performance (= 1.14.3)
181 | strscan (3.0.3)
182 | thor (1.2.1)
183 | timeout (0.3.0)
184 | tzinfo (2.0.4)
185 | concurrent-ruby (~> 1.0)
186 | unicode-display_width (2.2.0)
187 | websocket-driver (0.7.5)
188 | websocket-extensions (>= 0.1.0)
189 | websocket-extensions (0.1.5)
190 | zeitwerk (2.6.0)
191 |
192 | PLATFORMS
193 | arm64-darwin-21
194 | x86_64-darwin-21
195 | x86_64-linux
196 |
197 | DEPENDENCIES
198 | faker
199 | pry
200 | puma
201 | rails
202 | sqlite3
203 | standard
204 | unsplash_image!
205 |
206 | BUNDLED WITH
207 | 2.3.7
208 |
--------------------------------------------------------------------------------
/MIT-LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2022
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Unsplash Image Downloader & Helpers
2 |
3 | [](https://www.railsjazz.com)
4 |
5 | [](https://buymeacoffee.com/igorkasyanchuk)
6 |
7 | A CLI and a set of Rails helpers to get free images from [Unsplash](https://unsplash.com/).
8 |
9 | This is the easiest way to fill your Rails app with real photos.
10 |
11 | ## Usage
12 |
13 | 1. as Rails helper to generate dummy images:
14 | ```ruby
15 | <%= image_tag unsplash_image_url(size: '300x200', tags: 'cat, dog') %>
16 |
17 | <%= image_tag unsplash_image_url(size: '800x600', tags: 'building') %>
18 |
19 | <%= image_tag unsplash_image_url(tags: 'nature') %>
20 | ```
21 |
22 | 2. as a tool to download images from Unsplash.com and use them for your seeds or specs.
23 |
24 | ```bash
25 | unsplash_image download --path images/cats --tags cat -n 20
26 | ```
27 |
28 | 3. If you need to have a `File` object with a random image.
29 |
30 | ```ruby
31 | file = UnsplashImage.tempfile(size: '500x500', tags: 'cat')
32 | ```
33 |
34 | ### CLI
35 |
36 | By default `unsplash_image download --path ./files` will download 10 random images into a `./files` folder.
37 |
38 | You can see list of all available options by running:
39 |
40 |
41 | ```bash
42 | unsplash_image --help download
43 | ```
44 |
45 | With additional options you can specify a destination folder, tags, resolution of the images.
46 |
47 |
48 | ### In your Rails app
49 |
50 | You can get random image url inside your views using `unsplash_image_url`.
51 |
52 | Example:
53 | ```erb
54 | <%= image_tag unsplash_image_url(size: '300x200', tags: 'cat, dog') %>
55 | ```
56 |
57 | Also you can get it as a file with `UnsplashImage.tempfile`.
58 |
59 | Example:
60 | ```ruby
61 | file = UnsplashImage.tempfile(size: '500x500', tags: 'cat')
62 | ```
63 |
64 | ## Installation
65 |
66 | Add this line to your application's Gemfile:
67 |
68 | ```ruby
69 | gem "unsplash_image"
70 | ```
71 |
72 | And then execute:
73 | ```bash
74 | $ bundle
75 | ```
76 |
77 | To use CLI anywhere in the system you can install gem globally:
78 |
79 | ```bash
80 | gem install unsplash_image
81 | ```
82 |
83 | ## Unit Tests
84 |
85 | We have simple tests, just run: `ruby test/unsplash_image_test.rb`.
86 |
87 | ## Contributing
88 |
89 | You are welcome to contribute. See list of `TODO's` below.
90 |
91 | ## TODO
92 |
93 | - allow caching downloaded files for performance improvement (eg using in factories)
94 | - check with older Rails versions
95 | - tests or specs
96 | - make stand-alone executable installable via `brew`, `apt get`, etc?
97 |
98 | ## License
99 |
100 | The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
101 |
102 | [](https://www.railsjazz.com/?utm_source=github&utm_medium=bottom&utm_campaign=unsplash_image)
104 |
105 | [](https://buymeacoffee.com/igorkasyanchuk)
106 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | require "bundler/setup"
2 |
3 | require "bundler/gem_tasks"
4 |
--------------------------------------------------------------------------------
/bin/test:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | $: << File.expand_path("../test", __dir__)
3 |
4 | require "bundler/setup"
5 | require "rails/plugin/test"
6 |
--------------------------------------------------------------------------------
/bin/unsplash_image:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require 'unsplash_image/cli'
3 |
4 | UnsplashImage::CLI.start
5 |
--------------------------------------------------------------------------------
/lib/tasks/unsplash_image_tasks.rake:
--------------------------------------------------------------------------------
1 | # desc "Explaining what the task does"
2 | # task :unsplash_image do
3 | # # Task goes here
4 | # end
5 |
--------------------------------------------------------------------------------
/lib/unsplash_image.rb:
--------------------------------------------------------------------------------
1 | require "unsplash_image/version"
2 | require "unsplash_image/helper"
3 | require "unsplash_image/download"
4 | require "unsplash_image/railtie" if defined?(::Rails)
5 |
6 | module UnsplashImage
7 | end
8 |
--------------------------------------------------------------------------------
/lib/unsplash_image/cli.rb:
--------------------------------------------------------------------------------
1 | require "thor"
2 |
3 | require "unsplash_image"
4 | require "pathname"
5 |
6 | module UnsplashImage
7 | class CLI < Thor
8 | package_name "UnsplashImage"
9 |
10 | map "-d" => :download
11 | map "--download" => :download
12 |
13 | default_task :info
14 |
15 | desc :info, "Print info about cli"
16 |
17 | method_option :version, type: :boolean, default: false, aliases: [:v], banner: "Print UnsplashImage version"
18 | def info
19 | if options[:version]
20 | puts "UnsplashImage #{UnsplashImage::VERSION}"
21 | else
22 | info = [
23 | "UnsplashImage #{UnsplashImage::VERSION}",
24 | "",
25 | "Usage example: ",
26 | " unsplash_image download --path spec/files -n 10",
27 | " unsplash_image download --path images/cats -s 400x400 --tags cat -n 20",
28 | " unsplash_image download --path files/ -s 300x300 --tags cat dogs birds -n 20",
29 | "",
30 | "run 'unsplash_image download' to see awailable options"
31 | ]
32 | puts info.join("\n")
33 | end
34 | end
35 |
36 | desc "download [OPTIONS]", "Download Unsplash images"
37 |
38 | long_desc <<-LONGDESC
39 | `unsplash_image download` will download random unsplash images on your PC
40 |
41 | Example:
42 |
43 | > $ unsplash_image download --path images/cats -s 400x400 --tags cat -n 20
44 | LONGDESC
45 |
46 | DEFAULT_COUNT = 10
47 | DEFAULT_PATH = "."
48 |
49 | method_option :size, type: :string, aliases: [:s], banner: "Specify image size. Example: -s 640x480"
50 | method_option :count, type: :numeric, aliases: [:n], banner: "Specify images count. Example: -n 10"
51 | method_option :path, type: :string, banner: "Specify folder. Example: --path images/cats"
52 | method_option :tags, type: :array, aliases: [:t], banner: "Specify tags. Example: -t cats"
53 | method_option :prefix, type: :string, banner: "Specify file name prefix. Example: --prefix cat_image"
54 | def download
55 | if options.keys.empty?
56 | invoke :help, ["download"]
57 | else
58 | prefix = if !!options[:prefix]
59 | options[:prefix]
60 | else
61 | !(options[:tags].nil? || options[:tags].empty?) ? options[:tags].join("_") : "image"
62 | end
63 | tags = options[:tags]&.join(" ").to_s
64 |
65 | base_path = Pathname.new(options[:path] || DEFAULT_PATH)
66 | FileUtils.mkdir_p(base_path)
67 |
68 | puts "Downloading images to #{base_path.absolute? ? base_path : base_path.realpath.relative_path_from(Dir.pwd)}"
69 | count = (options[:count] || DEFAULT_COUNT).to_i
70 | count.times do |i|
71 | filename = count == 1 ? "#{prefix}.jpeg" : "#{prefix}_#{i + 1}.jpeg"
72 | filename = filename.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "�").strip.tr("\u{202E}%$|:;/\t\r\n\\", "-")
73 | path = File.expand_path(filename, base_path)
74 | puts "Downloading #{filename}"
75 | UnsplashImage.tempfile(size: options[:size], filename: filename, tags: tags + (" " * i)) do |tempfile|
76 | File.write(path, tempfile.read)
77 | end
78 | end
79 | puts "Done!"
80 | end
81 | end
82 |
83 | class << self
84 | def exit_on_failure?
85 | true
86 | end
87 | end
88 | end
89 | end
90 |
--------------------------------------------------------------------------------
/lib/unsplash_image/download.rb:
--------------------------------------------------------------------------------
1 | require "open-uri"
2 | require "tempfile"
3 |
4 | module UnsplashImage
5 | module Download
6 | def tempfile(size: nil, filename: "image.jpeg", tags: nil)
7 | file = Tempfile.new(filename, binmode: true)
8 | begin
9 | file.write(URI.parse(UnsplashImage::Helper.unsplash_image_url(size: size, tags: tags)).read)
10 | file.rewind
11 | if block_given?
12 | yield file
13 | else
14 | file
15 | end
16 | ensure
17 | if block_given?
18 | file.close
19 | file.unlink
20 | end
21 | end
22 | end
23 | end
24 |
25 | extend Download
26 | end
27 |
--------------------------------------------------------------------------------
/lib/unsplash_image/helper.rb:
--------------------------------------------------------------------------------
1 | module UnsplashImage
2 | module Helper
3 | extend self
4 |
5 | BASE = "https://source.unsplash.com/random".freeze
6 |
7 | def unsplash_image_url(size: nil, tags: nil)
8 | options = [BASE]
9 |
10 | options << size if size
11 | options << "?#{tags}" if tags
12 |
13 | options.join("/")
14 | end
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/lib/unsplash_image/railtie.rb:
--------------------------------------------------------------------------------
1 | module UnsplashImage
2 | class Railtie < ::Rails::Railtie
3 | initializer "unsplash_image.helpers", before: :load_config_initializers do
4 | ActiveSupport.on_load :action_view do
5 | include UnsplashImage::Helper
6 | end
7 | end
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/lib/unsplash_image/version.rb:
--------------------------------------------------------------------------------
1 | module UnsplashImage
2 | VERSION = "0.1.1"
3 | end
4 |
--------------------------------------------------------------------------------
/test/dummy/Rakefile:
--------------------------------------------------------------------------------
1 | # Add your own tasks in files placed in lib/tasks ending in .rake,
2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3 |
4 | require_relative "config/application"
5 |
6 | Rails.application.load_tasks
7 |
--------------------------------------------------------------------------------
/test/dummy/app/assets/images/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/railsjazz/unsplash_image/e9f03829841cf2fcf781ca90101da1c42398fc7d/test/dummy/app/assets/images/.keep
--------------------------------------------------------------------------------
/test/dummy/app/assets/stylesheets/application.css:
--------------------------------------------------------------------------------
1 | /* Application styles */
2 |
--------------------------------------------------------------------------------
/test/dummy/app/channels/application_cable/channel.rb:
--------------------------------------------------------------------------------
1 | module ApplicationCable
2 | class Channel < ActionCable::Channel::Base
3 | end
4 | end
5 |
--------------------------------------------------------------------------------
/test/dummy/app/channels/application_cable/connection.rb:
--------------------------------------------------------------------------------
1 | module ApplicationCable
2 | class Connection < ActionCable::Connection::Base
3 | end
4 | end
5 |
--------------------------------------------------------------------------------
/test/dummy/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | end
3 |
--------------------------------------------------------------------------------
/test/dummy/app/controllers/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/railsjazz/unsplash_image/e9f03829841cf2fcf781ca90101da1c42398fc7d/test/dummy/app/controllers/concerns/.keep
--------------------------------------------------------------------------------
/test/dummy/app/controllers/home_controller.rb:
--------------------------------------------------------------------------------
1 | class HomeController < ApplicationController
2 | def index
3 | end
4 | end
5 |
--------------------------------------------------------------------------------
/test/dummy/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | module ApplicationHelper
2 | end
3 |
--------------------------------------------------------------------------------
/test/dummy/app/jobs/application_job.rb:
--------------------------------------------------------------------------------
1 | class ApplicationJob < ActiveJob::Base
2 | # Automatically retry jobs that encountered a deadlock
3 | # retry_on ActiveRecord::Deadlocked
4 |
5 | # Most jobs are safe to ignore if the underlying records are no longer available
6 | # discard_on ActiveJob::DeserializationError
7 | end
8 |
--------------------------------------------------------------------------------
/test/dummy/app/mailers/application_mailer.rb:
--------------------------------------------------------------------------------
1 | class ApplicationMailer < ActionMailer::Base
2 | default from: "from@example.com"
3 | layout "mailer"
4 | end
5 |
--------------------------------------------------------------------------------
/test/dummy/app/models/application_record.rb:
--------------------------------------------------------------------------------
1 | class ApplicationRecord < ActiveRecord::Base
2 | primary_abstract_class
3 | end
4 |
--------------------------------------------------------------------------------
/test/dummy/app/models/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/railsjazz/unsplash_image/e9f03829841cf2fcf781ca90101da1c42398fc7d/test/dummy/app/models/concerns/.keep
--------------------------------------------------------------------------------
/test/dummy/app/views/home/index.html.erb:
--------------------------------------------------------------------------------
1 |
You may have mistyped the address or the page may have moved.
63 |If you are the application owner check the logs for more information.
65 |Maybe you tried to change something you didn't have access to.
63 |If you are the application owner check the logs for more information.
65 |If you are the application owner check the logs for more information.
64 |