jimothy 0.0.22 → 0.0.34

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
  SHA256:
3
- metadata.gz: 72719933f1723c69f04cc39c6ed0b5593c5ad8581a089ed64402fec90b6e0a20
4
- data.tar.gz: 0401a2f58aafbd2ecd557242511180fb6d140c94632f7230ebdb53aa3ae5a7d4
3
+ metadata.gz: d4420439db60d5fa2d2aec818cba4c0c63b0cf6fc342b703eee0196757071ea3
4
+ data.tar.gz: 9facbe2f644fb523c087d5cb90815775bc127fab816c66556bd4a57ed13664c7
5
5
  SHA512:
6
- metadata.gz: 306cc03ab4d64a54018c8d92e1fcfc51a924824c71bd998500d585d8b9a2451e06432a1cd2827bbf0fbb0f86b3e2142e2cb0d17cfbe46e7c7cb4d7ecaae8afa3
7
- data.tar.gz: c0242c630f996ef7a80e924efd43cf218143cd78d47cf188f5454dedcf97cf652c7219924ce87b486e93e47ce28408a8d0e9c8d98af96d6f96d62bd23728565b
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.22"
2
+ VERSION = "0.0.34"
3
3
  end
data/lib/jimothy.rb CHANGED
@@ -8,6 +8,15 @@ GEM_IMAGE_PATH = "#{GEM_ROOT}/lib/jimothy/images/"
8
8
  RAILS_IMAGE_PATH = "/app/assets/images/"
9
9
 
10
10
  module Jimothy
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
+
11
20
  def self.get_users
12
21
  users = JSON.parse(IO.read("#{JSON_PATH}"))['users']
13
22
  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.22
4
+ version: 0.0.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark McDermott
@@ -43,6 +43,7 @@ files:
43
43
  - app/models/jimothy/application_record.rb
44
44
  - app/views/layouts/jimothy/application.html.erb
45
45
  - config/routes.rb
46
+ - lib/generators/jimothy/install_generator.rb
46
47
  - lib/jimothy.rb
47
48
  - lib/jimothy/engine.rb
48
49
  - lib/jimothy/images/andy-bernard.png