jimothy 0.0.21 → 0.0.34

Sign up to get free protection for your applications and to get access to all the features.
Files changed (24) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -19
  3. data/lib/generators/jimothy/install_generator.rb +25 -0
  4. data/{app/assets/images/jimothy → lib/jimothy/images}/andy-bernard.png +0 -0
  5. data/{app/assets/images/jimothy → lib/jimothy/images}/angela-martin.png +0 -0
  6. data/{app/assets/images/jimothy → lib/jimothy/images}/creed-bratton.png +0 -0
  7. data/{app/assets/images/jimothy → lib/jimothy/images}/darryl-philbin.png +0 -0
  8. data/{app/assets/images/jimothy → lib/jimothy/images}/dwight-schrute.png +0 -0
  9. data/{app/assets/images/jimothy → lib/jimothy/images}/erin-hannon.png +0 -0
  10. data/{app/assets/images/jimothy → lib/jimothy/images}/flonkerton.jpg +0 -0
  11. data/{app/assets/images/jimothy → lib/jimothy/images}/jim-halpert.png +0 -0
  12. data/{app/assets/images/jimothy → lib/jimothy/images}/kelly-kapoor.png +0 -0
  13. data/{app/assets/images/jimothy → lib/jimothy/images}/kevin-malone.png +0 -0
  14. data/{app/assets/images/jimothy → lib/jimothy/images}/meredith-palmer.png +0 -0
  15. data/{app/assets/images/jimothy → lib/jimothy/images}/michael-scott.png +0 -0
  16. data/{app/assets/images/jimothy → lib/jimothy/images}/oscar-martinez.png +0 -0
  17. data/{app/assets/images/jimothy → lib/jimothy/images}/pam-beesly.png +0 -0
  18. data/{app/assets/images/jimothy → lib/jimothy/images}/phyllis-vance.png +0 -0
  19. data/{app/assets/images/jimothy → lib/jimothy/images}/ryan-howard.png +0 -0
  20. data/{app/assets/images/jimothy → lib/jimothy/images}/stanley-hudson.png +0 -0
  21. data/{app/assets/images/jimothy → lib/jimothy/images}/toby-flenderson.png +0 -0
  22. data/lib/jimothy/version.rb +1 -1
  23. data/lib/jimothy.rb +28 -4
  24. metadata +20 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 250781dcd85311922e16ecc05c6b52f7203164518cabb9b4777214592df06dce
4
- data.tar.gz: c33365192289c9b6354314129db804b743916bd293d0e9beb8f009368302b561
3
+ metadata.gz: d4420439db60d5fa2d2aec818cba4c0c63b0cf6fc342b703eee0196757071ea3
4
+ data.tar.gz: 9facbe2f644fb523c087d5cb90815775bc127fab816c66556bd4a57ed13664c7
5
5
  SHA512:
6
- metadata.gz: b24ef3f29269cdce06387f9e3c2515d8c581d891323034b4fd9ede6757bbeaf4acb0f702fc5b4cc089bbab7e867f0e61700458f708af8419dbc376e0188f28d0
7
- data.tar.gz: 8c13f04464ba632d7896c25a0c552a6b4f3079f7160de28217ac29c9a420f86685688c8481db8151da93a5e57f048ea91160af384f842ebeaa4acc4be0267f82
6
+ metadata.gz: 9643cb22e85a3451fd998128020532c71660275a24787d03bdaa3b53ee8f58aad0d91d4ace9ae692208c9e3d158e4ddb21225242b8b37a365693491e84952172
7
+ data.tar.gz: 5907c72c488575a587584c83402fe01327e63e841bc781e0df48134d081320895a81a3f8bffa8bc09ecc37fc84da90a993b65c10008570b9c60a5bb880592b13
data/README.md CHANGED
@@ -1,28 +1,42 @@
1
1
  # Jimothy
2
- Short description and motivation.
2
+ Placeholder user data from The Office
3
3
 
4
- ## Usage
5
- How to use my plugin.
4
+ ![The office characters](https://github.com/mark-mcdermott/jimothy/blob/main/lib/jimothy/images/flonkerton.jpg)
6
5
 
7
- ## Installation
8
- Add this line to your application's Gemfile:
6
+ ## What This Does
9
7
 
10
- ```ruby
11
- gem "jimothy"
12
- ```
8
+ Quickly seed amusing placeholder user data for your rails toy app or prototype app. Generate the names, emails and profile pictures of eighteen characters from The Office.
13
9
 
14
- And then execute:
15
- ```bash
16
- $ bundle
17
- ```
10
+ ## Why
11
+
12
+ This is obviously a (much) less robust version of something like Faker (https://github.com/faker-ruby/faker). But I built it to be more reliable than Faker, with more solid data. Faker is great for what it does, but if you generate users from TV data, sometimes users get weird names like "Skinny Pete", where "Pete" isn't really a last name and it can mess up your data. Yeah it's just placeholder data, but we want it to look right.
13
+
14
+ ## Usage (Quick, Using Custom Generator)
15
+ - Add `gem "jimothy"` to your `Gemfile`
16
+ - Run `bundle install`
17
+ - Run `rails g jimothy:install`
18
+ - This will scaffold user model/views, import images, seed users and add an image tag to the user view's `_user.html.erb` partial.
18
19
 
19
- Or install it yourself as:
20
- ```bash
21
- $ gem install jimothy
20
+ ## Usage (Slow, Doing Everything By Hand)
21
+ - Add `gem "jimothy"` to your `Gemfile`
22
+ - Run `bundle install`
23
+ - You'll need a `User` model with `name`, `email` and `image` fields (all `string`s. Fastest way to do this is:
24
+ ```
25
+ rails generate scaffold User name:string email:string image:string
26
+ rails db:migrate
27
+ ```
28
+ - Add the following to your `db/seeds.rb` file:
29
+ ```
30
+ require "jimothy"
31
+ Jimothy::seed_users
22
32
  ```
33
+ - Run `rails db:seed`
34
+ - In `app/views/users/_user.html.erb`, change `<%= user.image %>` to `<%= image_tag user.image %>`
35
+ - Run `rails server` and go to `http://127.0.0.1:3000/users`
23
36
 
24
- ## Contributing
25
- Contribution directions go here.
37
+ ## Details
38
+ - Main methods (`seed_users`, etc) are in `lib/jimothy.rb`
39
+ - Initial user data is in a json file in `lib/jimothy/the-office-characters.json`
40
+ - Inital user images are in `lib/jimothy/images`
41
+ - I believe images in Rails engines are supposed to be directly available from the gem for use in a Rail app's asset pipeline, but I could not get this working and couldn't find sufficient documentation for this. So I just copy the images from the gem to the rails app (to `app/assets/images`) in the `import_images` method, which is called by the `seed_users` method.
26
42
 
27
- ## License
28
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,25 @@
1
+ require "rails/generators"
2
+ require "rails/generators/rails/resource/resource_generator"
3
+
4
+ module Jimothy
5
+ module Generators
6
+ class InstallGenerator < Rails::Generators::Base
7
+ def scaffold_users
8
+ %x(rails g scaffold user name email image)
9
+ %x(rails db:migrate)
10
+ end
11
+ def add_image_tag
12
+ gsub_file 'app/views/users/_user.html.erb',/<%= user.image %>/,'<%= image_tag user.image %>'
13
+ end
14
+ def empty_seed_file
15
+ gsub_file 'db/seeds.rb',/# This file should contain all the record creation needed to seed the database with its default values.\n# The data can then be loaded with the bin\/rails db:seed command \(or created alongside the database with db:setup\).\n#\n# Examples:\n#\n# movies = Movie.create\(\[\{ name: \"Star Wars\" \}, \{ name: \"Lord of the Rings\" \}\]\)\n# Character.create\(name: \"Luke\", movie: movies.first\)\n/,'.'
16
+ end
17
+ def add_jimothy_call
18
+ gsub_file 'db/seeds.rb',/./,"require \"jimothy\"\nJimothy::seed_users"
19
+ end
20
+ def seed_users
21
+ %x(rails db:seed)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Jimothy
2
- VERSION = "0.0.21"
2
+ VERSION = "0.0.34"
3
3
  end
data/lib/jimothy.rb CHANGED
@@ -3,18 +3,42 @@ require "jimothy/engine"
3
3
  require "json"
4
4
 
5
5
  GEM_ROOT = File.expand_path("../..", __FILE__)
6
+ JSON_PATH = "#{GEM_ROOT}/lib/jimothy/the-office-characters.json"
7
+ GEM_IMAGE_PATH = "#{GEM_ROOT}/lib/jimothy/images/"
8
+ RAILS_IMAGE_PATH = "/app/assets/images/"
6
9
 
7
10
  module Jimothy
8
-
11
+
12
+ class Railtie < Rails::Railtie
13
+ config.app_generators do |g|
14
+ g.templates.unshift File::expand_path('../../templates', __FILE__)
15
+ g.templates.unshift File::expand_path('../../templates/erb/scaffold/_user.html.erb.tt')
16
+ g.templates.unshift File::expand_path('../../templates/erb/scaffold/_user.html.erb')
17
+ end
18
+ end
19
+
9
20
  def self.get_users
10
- users = JSON.parse(IO.read("#{GEM_ROOT}/lib/jimothy/the-office-characters.json"))['users']
21
+ users = JSON.parse(IO.read("#{JSON_PATH}"))['users']
11
22
  end
12
23
 
13
24
  def self.seed_users
14
- users = get_users
15
- users.each do |user|
25
+ create_users
26
+ import_images
27
+ end
28
+
29
+ def self.create_users
30
+ get_users.each do |user|
16
31
  User.create(name: user['firstname'] + " " + user['lastname'], email: user['email'], image: user['image'])
17
32
  end
18
33
  end
19
34
 
35
+ def self.import_images
36
+ images = Dir["#{GEM_IMAGE_PATH}" + "*.png"]
37
+ images.each do |path|
38
+ image = path.split('/')[-1]
39
+ source = "#{GEM_IMAGE_PATH}" + image
40
+ target = "#{Rails.root}#{RAILS_IMAGE_PATH}" + image
41
+ FileUtils.cp(source, target)
42
+ end
43
+ end
20
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jimothy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark McDermott
@@ -35,24 +35,6 @@ files:
35
35
  - README.md
36
36
  - Rakefile
37
37
  - app/assets/config/jimothy_manifest.js
38
- - app/assets/images/jimothy/andy-bernard.png
39
- - app/assets/images/jimothy/angela-martin.png
40
- - app/assets/images/jimothy/creed-bratton.png
41
- - app/assets/images/jimothy/darryl-philbin.png
42
- - app/assets/images/jimothy/dwight-schrute.png
43
- - app/assets/images/jimothy/erin-hannon.png
44
- - app/assets/images/jimothy/flonkerton.jpg
45
- - app/assets/images/jimothy/jim-halpert.png
46
- - app/assets/images/jimothy/kelly-kapoor.png
47
- - app/assets/images/jimothy/kevin-malone.png
48
- - app/assets/images/jimothy/meredith-palmer.png
49
- - app/assets/images/jimothy/michael-scott.png
50
- - app/assets/images/jimothy/oscar-martinez.png
51
- - app/assets/images/jimothy/pam-beesly.png
52
- - app/assets/images/jimothy/phyllis-vance.png
53
- - app/assets/images/jimothy/ryan-howard.png
54
- - app/assets/images/jimothy/stanley-hudson.png
55
- - app/assets/images/jimothy/toby-flenderson.png
56
38
  - app/assets/stylesheets/jimothy/application.css
57
39
  - app/controllers/jimothy/application_controller.rb
58
40
  - app/helpers/jimothy/application_helper.rb
@@ -61,8 +43,27 @@ files:
61
43
  - app/models/jimothy/application_record.rb
62
44
  - app/views/layouts/jimothy/application.html.erb
63
45
  - config/routes.rb
46
+ - lib/generators/jimothy/install_generator.rb
64
47
  - lib/jimothy.rb
65
48
  - lib/jimothy/engine.rb
49
+ - lib/jimothy/images/andy-bernard.png
50
+ - lib/jimothy/images/angela-martin.png
51
+ - lib/jimothy/images/creed-bratton.png
52
+ - lib/jimothy/images/darryl-philbin.png
53
+ - lib/jimothy/images/dwight-schrute.png
54
+ - lib/jimothy/images/erin-hannon.png
55
+ - lib/jimothy/images/flonkerton.jpg
56
+ - lib/jimothy/images/jim-halpert.png
57
+ - lib/jimothy/images/kelly-kapoor.png
58
+ - lib/jimothy/images/kevin-malone.png
59
+ - lib/jimothy/images/meredith-palmer.png
60
+ - lib/jimothy/images/michael-scott.png
61
+ - lib/jimothy/images/oscar-martinez.png
62
+ - lib/jimothy/images/pam-beesly.png
63
+ - lib/jimothy/images/phyllis-vance.png
64
+ - lib/jimothy/images/ryan-howard.png
65
+ - lib/jimothy/images/stanley-hudson.png
66
+ - lib/jimothy/images/toby-flenderson.png
66
67
  - lib/jimothy/the-office-characters.json
67
68
  - lib/jimothy/version.rb
68
69
  - lib/tasks/jimothy_tasks.rake