jimothy 1.0.002 → 1.0.011

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -39
  3. data/app/assets/config/jimothy_manifest.js +1 -0
  4. data/{lib/jimothy → app/assets}/images/andy-bernard.png +0 -0
  5. data/{lib/jimothy → app/assets}/images/angela-martin.png +0 -0
  6. data/{lib/jimothy → app/assets}/images/creed-bratton.png +0 -0
  7. data/{lib/jimothy → app/assets}/images/darryl-philbin.png +0 -0
  8. data/{lib/jimothy → app/assets}/images/dwight-schrute.png +0 -0
  9. data/{lib/jimothy → app/assets}/images/erin-hannon.png +0 -0
  10. data/{lib/jimothy → app/assets}/images/flonkerton.jpg +0 -0
  11. data/{lib/jimothy → app/assets}/images/jim-halpert.png +0 -0
  12. data/{lib/jimothy → app/assets}/images/kelly-kapoor.png +0 -0
  13. data/{lib/jimothy → app/assets}/images/kevin-malone.png +0 -0
  14. data/{lib/jimothy → app/assets}/images/meredith-palmer.png +0 -0
  15. data/app/assets/images/michael-scott.jpg +0 -0
  16. data/{lib/jimothy → app/assets}/images/michael-scott.png +0 -0
  17. data/{lib/jimothy → app/assets}/images/oscar-martinez.png +0 -0
  18. data/{lib/jimothy → app/assets}/images/pam-beesly.png +0 -0
  19. data/{lib/jimothy → app/assets}/images/phyllis-vance.png +0 -0
  20. data/{lib/jimothy → app/assets}/images/ryan-howard.png +0 -0
  21. data/{lib/jimothy → app/assets}/images/screenshot.jpg +0 -0
  22. data/{lib/jimothy → app/assets}/images/stanley-hudson.png +0 -0
  23. data/{lib/jimothy → app/assets}/images/toby-flenderson.png +0 -0
  24. data/lib/generators/jimothy/install_generator.rb +44 -15
  25. data/lib/jimothy/version.rb +1 -1
  26. data/lib/jimothy.rb +15 -24
  27. metadata +25 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 255502c8c568226ce82080916eae0bdb0fb3073fb7372a5f036a34616608c473
4
- data.tar.gz: 73529e4e80f39edb1e56ded50686d4e6cd1d73b3f90fafe01aca155b19159f09
3
+ metadata.gz: d08a408d886553058d5d17a5ff41751d55de648763df93b85f6f689e57632033
4
+ data.tar.gz: 12c1a834d3ea3b19f948cbcc523f62f47fe7791af681bce9e920cdc1ae279c8b
5
5
  SHA512:
6
- metadata.gz: 0ad498d87ab805b1a66398df1390983da77558a0339ea0753ed731601051dfd2c5459f2b3faa095987dca41e509af8b2e17225d7a9140345c5afd2aeb62a66ab
7
- data.tar.gz: d9c4a066276e6ac01016030e4612645540a3583fe77500c698200e5150dca47d581237ffd7fe102986bc4da42d02583275d5b29332950ac046370a83d2a1d04b
6
+ metadata.gz: 74a299120ed1517dbd2c4c9518fdbef9a2e37c34579d4acbdb9444d8a787990a40f264d92377957fea34d50ec9ea7bc3e450f87d4ba40bd3c848e4309e5d8533
7
+ data.tar.gz: 2445363e3ca41e59ac68bd3a84d22c93a20d7638df8ebb3c6560474ad7ca1e4d30880c743326677da15bd98ef2c9cddde52bc3ddbec93dff96f9a666702fdcc6
data/README.md CHANGED
@@ -1,48 +1,28 @@
1
1
  # Jimothy
2
- Placeholder user data from The Office.
3
- Gem available at https://rubygems.org/gems/jimothy
2
+ Short description and motivation.
4
3
 
5
- ![The office characters](https://github.com/mark-mcdermott/jimothy/blob/main/lib/jimothy/images/flonkerton.jpg)
4
+ ## Usage
5
+ How to use my plugin.
6
6
 
7
- ## What This Does
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
8
9
 
9
- Quickly seed placeholder user data for your Rails toy app or prototype app. Generate the names, emails and profile pictures of eighteen characters from The Office.
10
-
11
- ## Why
12
-
13
- This is 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 for example, 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.
14
-
15
- ## Usage (Quick, Using Custom Generator)
16
- - (If you don't have an app already) Run `rails new testapp`
17
- - Add `gem "jimothy"` to your `Gemfile`
18
- - Run `bundle install`
19
- - Run `rails g jimothy:install`
20
- - This will scaffold user model/views, import images, seed users and add an image tag to the user view's `_user.html.erb` partial.
21
- - Run `rails server` and open `http://127.0.0.1:3000/users` - you should see the users from The Office.
22
-
23
- ![Jimothy screenshot](https://github.com/mark-mcdermott/jimothy/blob/main/lib/jimothy/images/screenshot.jpg)
24
-
25
- ## Usage (Slow, Doing Everything By Hand)
26
- - (If you don't have an app already) Run `rails new testapp`
27
- - Add `gem "jimothy"` to your `Gemfile`
28
- - Run `bundle install`
29
- - You'll need a `User` model with `name`, `email` and `image` fields (all `string`s). Fastest way to do this is:
30
- ```
31
- rails generate scaffold User name:string email:string image:string
32
- rails db:migrate
10
+ ```ruby
11
+ gem "jimothy"
33
12
  ```
34
- - Add the following to your `db/seeds.rb` file:
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
35
17
  ```
36
- require "jimothy"
37
- Jimothy::seed_users
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install jimothy
38
22
  ```
39
- - Run `rails db:seed`
40
- - In `app/views/users/_user.html.erb`, change `<%= user.image %>` to `<%= image_tag user.image %>`
41
- - Run `rails server` and go to `http://127.0.0.1:3000/users` - you should see the users from The Office.
42
23
 
43
- ## Details
44
- - Main methods (`seed_users`, etc) are in `lib/jimothy.rb`
45
- - Initial user data is in a json file in `lib/jimothy/the-office-characters.json`
46
- - Inital user images are in `lib/jimothy/images`
47
- - 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.
24
+ ## Contributing
25
+ Contribution directions go here.
48
26
 
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1 +1,2 @@
1
1
  //= link_directory ../stylesheets/jimothy .css
2
+ //= link_directory ../images
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
Binary file
File without changes
File without changes
File without changes
@@ -4,21 +4,50 @@ require "rails/generators/rails/resource/resource_generator"
4
4
  module Jimothy
5
5
  module Generators
6
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)
7
+ def install_jimothy
8
+ cyan = "\e[36m" # use cyan color for puts
9
+ # only run if User model doesn't exist yet
10
+ if !Dir[Rails.root + 'app/models/*.rb'].map { |path| path.split('/')[-1] }.include? 'user.rb'
11
+ puts "#{cyan}\n🦄 Scaffolding user model now."
12
+ # scaffold users
13
+ %x(rails g scaffold user name email image)
14
+ puts "🦄 User model/views scaffolding built."
15
+ %x(rails db:migrate)
16
+ puts "🦄 Database migrated."
17
+
18
+ # add image tag
19
+ gsub_file 'app/views/users/_user.html.erb',/<%= user.image %>/,'<%= image_tag user.image %>'
20
+ puts "#{cyan}🦄 _user view partial updated."
21
+
22
+ # empty seed file
23
+ if File.exists?('db/seeds.rb')
24
+ puts "🦄 Seed file exists - emptying the file now."
25
+ 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/,''
26
+ else
27
+ puts "🦄 Seed file does not exist. Creating now."
28
+ File.open("db/seeds.rb") {|f| f.write(".") }
29
+ end
30
+
31
+ # add jimothy call
32
+ seeds_file = File.read('db/seeds.rb')
33
+ if seeds_file.empty? # only paste in this Jimothy::seed_users if the previous empty_seed_file was successful (ie, don't add it again if it's already there)
34
+ puts "#{cyan}🦄 Seed file is empty - adding Jimothy::seed_users call now."
35
+ File.write('db/seeds.rb', "require \"jimothy\"\nJimothy::seed_users", mode: 'a+')
36
+ else
37
+ puts "🤔 Seed file is not empty - skipping adding Jimothy::seed_users call."
38
+ end
39
+
40
+ # seed users
41
+ puts "🦄 Seeding users now."
42
+ %x(rails db:seed)
43
+
44
+ # add gem manifest to app manifest
45
+ puts "🦄 Adding jimothy gem manifest to app manifest now.\n"
46
+ File.write('app/assets/config/manifest.js', '//= link jimothy_manifest.js', mode: 'a+')
47
+ else
48
+ puts "#{cyan}\n🤔 Error: user model already exists. Skipping jimothy install."
49
+ end
50
+ puts "\e[0m" # restore puts color to normal
22
51
  end
23
52
  end
24
53
  end
@@ -1,3 +1,3 @@
1
1
  module Jimothy
2
- VERSION = "1.0.002"
2
+ VERSION = "1.0.011"
3
3
  end
data/lib/jimothy.rb CHANGED
@@ -8,37 +8,28 @@ 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
-
20
11
  def self.get_users
21
12
  users = JSON.parse(IO.read("#{JSON_PATH}"))['users']
22
13
  end
23
14
 
24
15
  def self.seed_users
25
- create_users
26
- import_images
27
- end
28
-
29
- def self.create_users
30
16
  get_users.each do |user|
31
17
  User.create(name: user['firstname'] + " " + user['lastname'], email: user['email'], image: user['image'])
32
18
  end
33
19
  end
34
20
 
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
44
- end
21
+ # def self.seed_users
22
+ # create_users
23
+ # import_images
24
+ # end
25
+
26
+ # def self.import_images
27
+ # images = Dir["#{GEM_IMAGE_PATH}" + "*.png"] # TODO: there are jpgs in this folder for the readme, move them to a different folder
28
+ # images.each do |path|
29
+ # image = path.split('/')[-1]
30
+ # source = "#{GEM_IMAGE_PATH}" + image
31
+ # target = "#{Rails.root}#{RAILS_IMAGE_PATH}" + image
32
+ # FileUtils.cp(source, target)
33
+ # end
34
+ # end
35
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jimothy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.002
4
+ version: 1.0.011
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark McDermott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-21 00:00:00.000000000 Z
11
+ date: 2023-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,9 +24,7 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 7.0.4.2
27
- description: Quickly seed placeholder user data for your Rails toy app or prototype
28
- app. Generate the names, emails and profile pictures of eighteen characters from
29
- The Office.
27
+ description: Description of Jimothy.
30
28
  email:
31
29
  - mark@markmcdermott.io
32
30
  executables: []
@@ -37,6 +35,26 @@ files:
37
35
  - README.md
38
36
  - Rakefile
39
37
  - app/assets/config/jimothy_manifest.js
38
+ - app/assets/images/andy-bernard.png
39
+ - app/assets/images/angela-martin.png
40
+ - app/assets/images/creed-bratton.png
41
+ - app/assets/images/darryl-philbin.png
42
+ - app/assets/images/dwight-schrute.png
43
+ - app/assets/images/erin-hannon.png
44
+ - app/assets/images/flonkerton.jpg
45
+ - app/assets/images/jim-halpert.png
46
+ - app/assets/images/kelly-kapoor.png
47
+ - app/assets/images/kevin-malone.png
48
+ - app/assets/images/meredith-palmer.png
49
+ - app/assets/images/michael-scott.jpg
50
+ - app/assets/images/michael-scott.png
51
+ - app/assets/images/oscar-martinez.png
52
+ - app/assets/images/pam-beesly.png
53
+ - app/assets/images/phyllis-vance.png
54
+ - app/assets/images/ryan-howard.png
55
+ - app/assets/images/screenshot.jpg
56
+ - app/assets/images/stanley-hudson.png
57
+ - app/assets/images/toby-flenderson.png
40
58
  - app/assets/stylesheets/jimothy/application.css
41
59
  - app/controllers/jimothy/application_controller.rb
42
60
  - app/helpers/jimothy/application_helper.rb
@@ -48,29 +66,10 @@ files:
48
66
  - lib/generators/jimothy/install_generator.rb
49
67
  - lib/jimothy.rb
50
68
  - lib/jimothy/engine.rb
51
- - lib/jimothy/images/andy-bernard.png
52
- - lib/jimothy/images/angela-martin.png
53
- - lib/jimothy/images/creed-bratton.png
54
- - lib/jimothy/images/darryl-philbin.png
55
- - lib/jimothy/images/dwight-schrute.png
56
- - lib/jimothy/images/erin-hannon.png
57
- - lib/jimothy/images/flonkerton.jpg
58
- - lib/jimothy/images/jim-halpert.png
59
- - lib/jimothy/images/kelly-kapoor.png
60
- - lib/jimothy/images/kevin-malone.png
61
- - lib/jimothy/images/meredith-palmer.png
62
- - lib/jimothy/images/michael-scott.png
63
- - lib/jimothy/images/oscar-martinez.png
64
- - lib/jimothy/images/pam-beesly.png
65
- - lib/jimothy/images/phyllis-vance.png
66
- - lib/jimothy/images/ryan-howard.png
67
- - lib/jimothy/images/screenshot.jpg
68
- - lib/jimothy/images/stanley-hudson.png
69
- - lib/jimothy/images/toby-flenderson.png
70
69
  - lib/jimothy/the-office-characters.json
71
70
  - lib/jimothy/version.rb
72
71
  - lib/tasks/jimothy_tasks.rake
73
- homepage: https://github.com/mark-mcdermott/jimothy/
72
+ homepage: https://github.com/mark-mcdermott/jimothy
74
73
  licenses:
75
74
  - MIT
76
75
  metadata: {}
@@ -92,5 +91,5 @@ requirements: []
92
91
  rubygems_version: 3.3.7
93
92
  signing_key:
94
93
  specification_version: 4
95
- summary: Placeholder Rails users from The Office
94
+ summary: Summary of Jimothy.
96
95
  test_files: []