webring-rails 1.0.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.
Files changed (30) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +598 -0
  4. data/app/assets/javascripts/webring/widget.js +224 -0
  5. data/app/controllers/webring/application_controller.rb +5 -0
  6. data/app/controllers/webring/members_controller.rb +60 -0
  7. data/app/controllers/webring/navigation_controller.rb +68 -0
  8. data/app/controllers/webring/widget_controller.rb +31 -0
  9. data/app/helpers/webring/application_helper.rb +4 -0
  10. data/app/jobs/webring/application_job.rb +4 -0
  11. data/app/mailers/webring/application_mailer.rb +6 -0
  12. data/app/models/concerns/webring/navigation.rb +60 -0
  13. data/app/models/webring/application_record.rb +5 -0
  14. data/app/models/webring/member.rb +31 -0
  15. data/config/routes.rb +8 -0
  16. data/lib/generators/USAGE +25 -0
  17. data/lib/generators/webring/controller/controller_generator.rb +49 -0
  18. data/lib/generators/webring/controller/templates/navigation_controller.rb +61 -0
  19. data/lib/generators/webring/install/install_generator.rb +31 -0
  20. data/lib/generators/webring/install/templates/AFTER_INSTALL +63 -0
  21. data/lib/generators/webring/member/member_generator.rb +55 -0
  22. data/lib/generators/webring/member/templates/AFTER_INSTALL +38 -0
  23. data/lib/generators/webring/member/templates/migration.rb +15 -0
  24. data/lib/generators/webring/member/templates/model.rb +31 -0
  25. data/lib/generators/webring/shared/route_injector.rb +40 -0
  26. data/lib/generators/webring_generator.rb +17 -0
  27. data/lib/webring/engine.rb +35 -0
  28. data/lib/webring/version.rb +3 -0
  29. data/lib/webring_rails.rb +5 -0
  30. metadata +115 -0
@@ -0,0 +1,63 @@
1
+ ==============================================
2
+ Webring Engine Has Been Successfully Installed!
3
+ ==============================================
4
+
5
+ The Webring engine has been mounted at '/webring' in your application. Below are
6
+ the next steps to complete the webring setup and customization options.
7
+
8
+ 1. Configure Your Members Model
9
+ -------------------------------
10
+ Generate a member model to store information about sites in your webring:
11
+
12
+ $ rails generate webring:member
13
+
14
+ This will:
15
+ - Create a Webring::Member model in app/models/webring/member.rb
16
+ - Create a migration to set up the webring_members table
17
+ - Add appropriate database indexes
18
+
19
+ After generating the model, run the migration:
20
+
21
+ $ rails db:migrate
22
+
23
+ 2. Generate Navigation Controller [Optional]
24
+ --------------------------------------------
25
+ Generate a navigation controller to handle navigation between webring members:
26
+
27
+ $ rails generate webring:controller
28
+
29
+ This will:
30
+ - Create the Webring::NavigationController in app/controllers/webring/navigation_controller.rb
31
+ - Add navigation routes to your routes.rb file:
32
+ - GET /webring/next - Navigate to the next site
33
+ - GET /webring/previous - Navigate to the previous site
34
+ - GET /webring/random - Navigate to a random site
35
+
36
+ 3. Customize Your Routes [Optional]
37
+ ----------------------------------
38
+ The engine is mounted at '/webring' by default. You can change this in your routes.rb file:
39
+
40
+ # Original mount point
41
+ mount Webring::Engine => '/webring', as: 'webring'
42
+
43
+ # Example custom mount point
44
+ mount Webring::Engine => '/network', as: 'webring'
45
+
46
+ 4. Add Webring Navigation UI Elements
47
+ ------------------------------------
48
+ Add navigation links to your views to enable users to navigate through the webring:
49
+
50
+ <%= link_to 'Next Site', webring.next_path(source_member_uid: your_member.uid) %>
51
+ <%= link_to 'Previous Site', webring.previous_path(source_member_uid: your_member.uid) %>
52
+ <%= link_to 'Random Site', webring.random_path %>
53
+
54
+ Note: Replace 'your_member.uid' with the actual UID of your site in the webring.
55
+ If you're building a standalone webring hub, you can omit the source_member_uid parameter.
56
+
57
+ 5. Managing Webring Members
58
+ --------------------------
59
+ You can add members to your webring using the Webring::Member model:
60
+
61
+ Webring::Member.create(name: 'Example Site', url: 'https://example.com')
62
+
63
+ Consider building an admin interface to manage your webring members.
@@ -0,0 +1,55 @@
1
+ require 'rails/generators/active_record'
2
+ require 'rails/generators/named_base'
3
+ require_relative '../shared/route_injector'
4
+
5
+ module Webring
6
+ module Generators
7
+ # @description The MemberGenerator creates the Member model, which is the core of the webring
8
+ # It creates both the model file and a migration to create the database table
9
+ #
10
+ # @usage Run: rails generate webring:member
11
+ #
12
+ # @example Generated Member model has the following attributes:
13
+ # # uid - A unique identifier for the member (automatically generated)
14
+ # # name - The name of the member site (defaults to URL if not provided)
15
+ # # url - The URL of the member site (required)
16
+ #
17
+ # @note After running this generator, you should run the migration with:
18
+ # rails db:migrate
19
+ class MemberGenerator < Rails::Generators::Base
20
+ include Rails::Generators::Migration
21
+ include Shared::RouteInjector
22
+
23
+ source_root File.expand_path('templates', __dir__)
24
+
25
+ desc 'Creates a Webring::Member model and necessary migration for storing webring members'
26
+
27
+ # Creates a migration file to create the webring_members table
28
+ # @return [void]
29
+ def create_migration_file
30
+ migration_template 'migration.rb', 'db/migrate/create_webring_members.rb'
31
+ end
32
+
33
+ # Creates the Member model file based on the template
34
+ # @return [void]
35
+ def create_model_file
36
+ template 'model.rb', 'app/models/webring/member.rb'
37
+ end
38
+
39
+ # Generates the next migration number for the migration file
40
+ # This is required by Rails::Generators::Migration
41
+ # @param dirname [String] The directory where migrations are stored
42
+ # @return [Integer] The next migration number
43
+ def self.next_migration_number(dirname)
44
+ next_migration_number = current_migration_number(dirname) + 1
45
+ ActiveRecord::Migration.next_migration_number(next_migration_number)
46
+ end
47
+
48
+ # Displays the README with next steps after installation
49
+ # @return [void]
50
+ def show_readme
51
+ readme 'AFTER_INSTALL' if behavior == :invoke
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,38 @@
1
+ ==============================================
2
+ Webring::Member Model Has Been Generated!
3
+ ==============================================
4
+
5
+ The Member model is the core component of the webring, representing each site
6
+ in your webring network. Follow these steps to complete the setup:
7
+
8
+ 1. Run Database Migration
9
+ ------------------------
10
+ Apply the migration to create the webring_members table:
11
+
12
+ $ rails db:migrate
13
+
14
+ 2. Review and Customize the Model
15
+ -------------------------------
16
+ The generated model is located at:
17
+ app/models/webring/member.rb
18
+
19
+ The Member model has the following attributes:
20
+ - uid: A unique identifier automatically generated for each member (32-character hex)
21
+ - name: The name of the member site (optional, defaults to URL if not provided)
22
+ - url: The URL of the member site (required)
23
+
24
+ 3. Adding Members to Your Webring
25
+ -------------------------------
26
+ You can add members to your webring using the Webring::Member model:
27
+
28
+ Webring::Member.create(name: 'Example Site', url: 'https://example.com')
29
+
30
+ The uid will be automatically generated if not provided.
31
+
32
+ 4. Next Steps
33
+ -----------
34
+ Consider generating the navigation controller to enable navigation between webring members:
35
+
36
+ $ rails generate webring:controller
37
+
38
+ This will create routes and controller actions for webring navigation.
@@ -0,0 +1,15 @@
1
+ class CreateWebringMembers < ActiveRecord::Migration<%= "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" %>
2
+ def change
3
+ create_table :webring_members do |t|
4
+ t.string :uid, null: false, limit: 32
5
+ t.string :name
6
+ t.string :url, null: false
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :webring_members, :uid, unique: true
12
+ add_index :webring_members, :name, unique: true
13
+ add_index :webring_members, :url, unique: true
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ module Webring
2
+ class Member < ApplicationRecord
3
+ extend Webring::Navigation
4
+
5
+ UID_LENGTH = 16 # 32-character hex string
6
+
7
+ validates :url, presence: true, uniqueness: true
8
+ validates :name, uniqueness: true, if: -> { name.present? }
9
+ validates :uid, presence: true, uniqueness: true, length: { is: UID_LENGTH * 2 }
10
+
11
+ before_validation :generate_uid, if: -> { uid.blank? }
12
+ before_validation :set_name_from_url, if: -> { name.blank? && url.present? }
13
+
14
+ def to_param
15
+ uid
16
+ end
17
+
18
+ private
19
+
20
+ def generate_uid
21
+ loop do
22
+ self.uid = SecureRandom.hex(UID_LENGTH)
23
+ break unless self.class.exists?(uid: uid)
24
+ end
25
+ end
26
+
27
+ def set_name_from_url
28
+ self.name = url
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,40 @@
1
+ module Webring
2
+ module Generators
3
+ module Shared
4
+ # @description The RouteInjector module provides utility methods for injecting routes
5
+ # into the application's routes.rb file. It's used by various Webring generators
6
+ # to add their respective routes.
7
+ #
8
+ # @usage Include this module in a generator class:
9
+ # include Webring::Generators::Shared::RouteInjector
10
+ #
11
+ # @example
12
+ # # Then you can use the inject_webring_routes method:
13
+ # inject_webring_routes("namespace :webring do\n resources :members\nend")
14
+ module RouteInjector
15
+ private
16
+
17
+ # Injects routes into the application's routes.rb file
18
+ # If the Webring engine is already mounted, this will add the routes
19
+ # right after the engine's mount point. Otherwise, it will add them
20
+ # to the end of the routes file.
21
+ #
22
+ # @param route_content [String] The routes to be added
23
+ # @return [void]
24
+ def inject_webring_routes(route_content)
25
+ cleared_route_content = route_content.gsub(/^/, ' ')
26
+ routes_file = 'config/routes.rb'
27
+ mount_point = "mount Webring::Engine => '/webring', as: 'webring'\n"
28
+
29
+ if File.read(routes_file).include?(mount_point)
30
+ inject_into_file routes_file, after: mount_point do
31
+ "\n#{cleared_route_content}"
32
+ end
33
+ else
34
+ route "#{cleared_route_content}\n"
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ module Webring
2
+ module Generators
3
+ class WebringGenerator < Rails::Generators::NamedBase
4
+ namespace 'webring'
5
+
6
+ desc 'Creates a Webring configuration for the given model name'
7
+
8
+ def invoke_webring_member
9
+ invoke 'webring:member'
10
+ end
11
+
12
+ def invoke_webring_controller
13
+ invoke 'webring:controller'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ module Webring
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Webring
4
+
5
+ # configure app generators for templates
6
+ config.app_generators do |g|
7
+ g.templates.unshift File.expand_path('../../generators/webring/templates', __dir__)
8
+ end
9
+
10
+ # load generators properly for Rails compatibility
11
+ initializer 'webring.load_generators' do |app|
12
+ generators_path = File.expand_path('../../generators', __dir__)
13
+
14
+ # add generators path to Rails paths
15
+ if defined?(Rails.application.config.generators.templates)
16
+ Rails.application.config.generators.templates.unshift(File.join(generators_path, 'webring/templates'))
17
+ end
18
+
19
+ # ensure the generators path exists in the app's paths
20
+ if app.config.respond_to?(:paths)
21
+ app.config.paths['lib/generators'] ||= []
22
+ app.config.paths['lib/generators'] << generators_path
23
+ end
24
+ end
25
+
26
+ # add migrations from the engine to the main app
27
+ initializer 'webring.append_migrations' do |app|
28
+ unless app.root.to_s == root.to_s
29
+ config.paths['db/migrate'].expanded.each do |expanded_path|
30
+ app.config.paths['db/migrate'] << expanded_path
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Webring
2
+ VERSION = '1.0.0'.freeze
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'webring/version'
2
+ require 'webring/engine'
3
+
4
+ module Webring
5
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webring-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nikita Shkoda
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '7.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.75'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.75'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.31'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.31'
55
+ description: Mountable Rails Engine for webring implementation with an embeddable
56
+ styled widget
57
+ email:
58
+ - lstpsche@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - MIT-LICENSE
64
+ - README.md
65
+ - app/assets/javascripts/webring/widget.js
66
+ - app/controllers/webring/application_controller.rb
67
+ - app/controllers/webring/members_controller.rb
68
+ - app/controllers/webring/navigation_controller.rb
69
+ - app/controllers/webring/widget_controller.rb
70
+ - app/helpers/webring/application_helper.rb
71
+ - app/jobs/webring/application_job.rb
72
+ - app/mailers/webring/application_mailer.rb
73
+ - app/models/concerns/webring/navigation.rb
74
+ - app/models/webring/application_record.rb
75
+ - app/models/webring/member.rb
76
+ - config/routes.rb
77
+ - lib/generators/USAGE
78
+ - lib/generators/webring/controller/controller_generator.rb
79
+ - lib/generators/webring/controller/templates/navigation_controller.rb
80
+ - lib/generators/webring/install/install_generator.rb
81
+ - lib/generators/webring/install/templates/AFTER_INSTALL
82
+ - lib/generators/webring/member/member_generator.rb
83
+ - lib/generators/webring/member/templates/AFTER_INSTALL
84
+ - lib/generators/webring/member/templates/migration.rb
85
+ - lib/generators/webring/member/templates/model.rb
86
+ - lib/generators/webring/shared/route_injector.rb
87
+ - lib/generators/webring_generator.rb
88
+ - lib/webring/engine.rb
89
+ - lib/webring/version.rb
90
+ - lib/webring_rails.rb
91
+ homepage: https://github.com/lstpsche/webring_rails
92
+ licenses:
93
+ - MIT
94
+ metadata:
95
+ homepage_uri: https://github.com/lstpsche/webring_rails
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 3.2.3
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.5.7
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: WebRing plugin for Rails
115
+ test_files: []