bunko 0.2.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.
- checksums.yaml +7 -0
- data/.standard.yml +3 -0
- data/CHANGELOG.md +41 -0
- data/CLAUDE.md +351 -0
- data/LICENSE.txt +21 -0
- data/README.md +641 -0
- data/ROADMAP.md +519 -0
- data/Rakefile +10 -0
- data/lib/bunko/configuration.rb +180 -0
- data/lib/bunko/controllers/acts_as.rb +22 -0
- data/lib/bunko/controllers/collection.rb +160 -0
- data/lib/bunko/controllers.rb +5 -0
- data/lib/bunko/models/acts_as.rb +24 -0
- data/lib/bunko/models/post_methods/publishable.rb +51 -0
- data/lib/bunko/models/post_methods/sluggable.rb +47 -0
- data/lib/bunko/models/post_methods/word_countable.rb +76 -0
- data/lib/bunko/models/post_methods.rb +75 -0
- data/lib/bunko/models/post_type_methods.rb +18 -0
- data/lib/bunko/models.rb +6 -0
- data/lib/bunko/railtie.rb +22 -0
- data/lib/bunko/routing/mapper_methods.rb +103 -0
- data/lib/bunko/routing.rb +4 -0
- data/lib/bunko/version.rb +5 -0
- data/lib/bunko.rb +11 -0
- data/lib/tasks/bunko/add.rake +259 -0
- data/lib/tasks/bunko/helpers.rb +25 -0
- data/lib/tasks/bunko/install.rake +125 -0
- data/lib/tasks/bunko/sample_data.rake +128 -0
- data/lib/tasks/bunko/setup.rake +186 -0
- data/lib/tasks/support/sample_data_generator.rb +399 -0
- data/lib/tasks/templates/INSTALL.md +62 -0
- data/lib/tasks/templates/config/initializers/bunko.rb.tt +45 -0
- data/lib/tasks/templates/controllers/controller.rb.tt +25 -0
- data/lib/tasks/templates/controllers/pages_controller.rb.tt +29 -0
- data/lib/tasks/templates/db/migrate/create_post_types.rb.tt +14 -0
- data/lib/tasks/templates/db/migrate/create_posts.rb.tt +31 -0
- data/lib/tasks/templates/models/post.rb.tt +8 -0
- data/lib/tasks/templates/models/post_type.rb.tt +8 -0
- data/lib/tasks/templates/views/collections/index.html.erb.tt +67 -0
- data/lib/tasks/templates/views/collections/show.html.erb.tt +39 -0
- data/lib/tasks/templates/views/layouts/bunko_footer.html.erb.tt +3 -0
- data/lib/tasks/templates/views/layouts/bunko_nav.html.erb.tt +9 -0
- data/lib/tasks/templates/views/layouts/bunko_styles.html.erb.tt +3 -0
- data/lib/tasks/templates/views/pages/show.html.erb.tt +16 -0
- data/sig/bunko.rbs +4 -0
- metadata +116 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6accf7b30d2c8e9ac29136f02493055cbfef1489d18c02b485a43a6a01c158bb
|
|
4
|
+
data.tar.gz: eff50c704576748edb4509c4793c00dd30bc9d16000df29c3c41ee7cc3e4de1c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d71d7142ef376396ffd283a7a60422f9cca02fdd077c87aab77d2c2b23271215d49ec9c82b82c2d32f8c1e0ab436708b2d79708b88c2ec74c97dde27591890b4
|
|
7
|
+
data.tar.gz: 84cce284b6657cd4529abf01e6e06baa21e8d6117f922bb2a8fef5ca489be517a0c68a0b1f1d0ea0c608b967ab5c3eb1ac5afc1d91556f09437cff8a13df0de8
|
data/.standard.yml
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
## [Unreleased]
|
|
2
|
+
|
|
3
|
+
Building toward 1.0.0 release. Using 0.x versions during active development.
|
|
4
|
+
|
|
5
|
+
## [0.2.0] - 2025-11-14
|
|
6
|
+
|
|
7
|
+
First functional release of Bunko - a lightweight Rails CMS based on the "one model, infinite collections" philosophy.
|
|
8
|
+
|
|
9
|
+
**Core Features:**
|
|
10
|
+
- One `Post` model routes to many collections (`/blog/`, `/docs/`, `/changelog/`, etc.)
|
|
11
|
+
- Two-phase installation: `rails bunko:install` → `rails bunko:setup`
|
|
12
|
+
- Configuration-driven setup via `config/initializers/bunko.rb`
|
|
13
|
+
- Generated controllers, views, and routes with Pico CSS styling (easily customizable)
|
|
14
|
+
- Publishing workflow with draft/published/scheduled states
|
|
15
|
+
- Automatic slug generation and reading time calculation
|
|
16
|
+
- Post convenience methods: `excerpt`, `published_date`, `reading_time_text`
|
|
17
|
+
- Built-in pagination (no external dependencies)
|
|
18
|
+
|
|
19
|
+
**Static Pages:**
|
|
20
|
+
- `bunko_page` routing for standalone pages (About, Contact, Privacy)
|
|
21
|
+
- Shared `PagesController` with smart view resolution
|
|
22
|
+
- Same Post model, different post_type
|
|
23
|
+
|
|
24
|
+
**Smart Collections:**
|
|
25
|
+
- Aggregate multiple post types: `config.collection "resources", post_types: ["articles", "videos"]`
|
|
26
|
+
- Filter with scopes: `config.collection "long_reads" { |c| c.scope = -> { where("word_count > ?", 1500) } }`
|
|
27
|
+
|
|
28
|
+
**Sample Data Generator:**
|
|
29
|
+
- `rails bunko:sample_data` - Generate realistic posts for testing
|
|
30
|
+
- HTML and Markdown format support
|
|
31
|
+
- Configurable word counts, post counts, and content styles
|
|
32
|
+
|
|
33
|
+
**Routing:**
|
|
34
|
+
- `bunko_collection :blog` - Simple DSL for content routes
|
|
35
|
+
- `bunko_page :about` - Single-page routes without collection index
|
|
36
|
+
- Automatic hyphenation: `:case_study` → `/case-study/`
|
|
37
|
+
|
|
38
|
+
## [0.1.0] - 2025-11-09
|
|
39
|
+
|
|
40
|
+
- Initial release to register gem name on RubyGems
|
|
41
|
+
- Placeholder release with basic gem structure and working tests
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
Bunko is a Rails gem that provides a lightweight CMS structure based on a "one model, infinite collections" philosophy. It allows developers to create multiple content collections (blog, docs, changelog, tutorials, etc.) without duplicate code or migrations, routing all content through a single Post model.
|
|
8
|
+
|
|
9
|
+
**Core Philosophy:**
|
|
10
|
+
- Out-of-the-box blog without the bloat
|
|
11
|
+
- One Post model routes to many collections (`/blog/`, `/docs/`, `/changelog/`, etc.)
|
|
12
|
+
- Database, editor, and view layer agnostic
|
|
13
|
+
- No opinions on JavaScript, CSS, authentication, authorization, or admin UI
|
|
14
|
+
- Conventions over configuration with escape hatches
|
|
15
|
+
|
|
16
|
+
## Development Commands
|
|
17
|
+
|
|
18
|
+
### Testing
|
|
19
|
+
```bash
|
|
20
|
+
# Run all tests
|
|
21
|
+
rake test
|
|
22
|
+
# or
|
|
23
|
+
bundle exec rake test
|
|
24
|
+
|
|
25
|
+
# Run a single test file
|
|
26
|
+
ruby test/test_bunko.rb
|
|
27
|
+
|
|
28
|
+
# Run a specific test
|
|
29
|
+
ruby test/test_bunko.rb --name test_that_it_has_a_version_number
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Linting
|
|
33
|
+
```bash
|
|
34
|
+
# Run Standard Ruby linter
|
|
35
|
+
rake standard
|
|
36
|
+
# or
|
|
37
|
+
bundle exec standardrb
|
|
38
|
+
|
|
39
|
+
# Auto-fix linting issues
|
|
40
|
+
bundle exec standardrb --fix
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Default Task (Tests + Linting)
|
|
44
|
+
```bash
|
|
45
|
+
# Runs both test suite and standard linter
|
|
46
|
+
rake
|
|
47
|
+
# or
|
|
48
|
+
bundle exec rake
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Console
|
|
52
|
+
```bash
|
|
53
|
+
# Interactive console for experimentation
|
|
54
|
+
bin/console
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Setup
|
|
58
|
+
```bash
|
|
59
|
+
# Install dependencies after cloning
|
|
60
|
+
bin/setup
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Gem Management
|
|
64
|
+
```bash
|
|
65
|
+
# Install gem locally
|
|
66
|
+
bundle exec rake install
|
|
67
|
+
|
|
68
|
+
# Build gem file
|
|
69
|
+
bundle exec rake build
|
|
70
|
+
|
|
71
|
+
# Release new version (updates version.rb, creates git tag, pushes to rubygems)
|
|
72
|
+
bundle exec rake release
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Project Structure
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
lib/
|
|
79
|
+
├── bunko/
|
|
80
|
+
│ ├── version.rb # Version constant
|
|
81
|
+
│ ├── configuration.rb # Configuration system with post_type DSL
|
|
82
|
+
│ ├── models/ # ActiveRecord model concerns
|
|
83
|
+
│ │ ├── acts_as.rb # acts_as_bunko_post/post_type macros
|
|
84
|
+
│ │ ├── post_methods.rb # Post behavior (concern)
|
|
85
|
+
│ │ └── post_type_methods.rb # PostType behavior (concern)
|
|
86
|
+
│ ├── controllers/ # ActionController concerns
|
|
87
|
+
│ │ ├── acts_as.rb # bunko_collection macro
|
|
88
|
+
│ │ └── collection.rb # Collection behavior (concern)
|
|
89
|
+
│ ├── routing/ # ActionDispatch routing extensions
|
|
90
|
+
│ │ └── mapper_methods.rb # bunko_collection DSL method
|
|
91
|
+
│ └── railtie.rb # Rails integration (loads rake tasks, routing)
|
|
92
|
+
└── tasks/
|
|
93
|
+
└── bunko/
|
|
94
|
+
├── setup.rake # rails bunko:setup task
|
|
95
|
+
├── add.rake # rails bunko:add[name] task
|
|
96
|
+
└── sample_data.rake # rails bunko:sample_data task
|
|
97
|
+
└── templates/ # Controller and view templates
|
|
98
|
+
├── controller.rb.tt
|
|
99
|
+
├── index.html.erb.tt
|
|
100
|
+
├── show.html.erb.tt
|
|
101
|
+
├── pages_controller.rb.tt # PagesController template for static pages
|
|
102
|
+
├── page_show.html.erb.tt # Default page view template
|
|
103
|
+
├── bunko_nav.html.erb.tt # Shared nav partial
|
|
104
|
+
├── bunko_styles.html.erb.tt # Shared styles partial (Pico CSS)
|
|
105
|
+
└── bunko_footer.html.erb.tt # Shared footer partial
|
|
106
|
+
test/
|
|
107
|
+
├── dummy/ # Rails dummy app for integration testing
|
|
108
|
+
├── models/ # Model tests (organized by functionality)
|
|
109
|
+
│ ├── post_scopes_test.rb # Query scopes (6 tests)
|
|
110
|
+
│ ├── post_slug_test.rb # Slug generation (10 tests)
|
|
111
|
+
│ ├── post_publishing_test.rb # Publishing workflow (11 tests)
|
|
112
|
+
│ ├── post_reading_time_test.rb # Reading time (7 tests)
|
|
113
|
+
│ ├── post_content_formatting_test.rb # Excerpt method (7 tests)
|
|
114
|
+
│ ├── post_date_formatting_test.rb # Date formatting (5 tests)
|
|
115
|
+
│ ├── post_meta_tags_test.rb # Meta tags (5 tests)
|
|
116
|
+
│ └── post_type_test.rb # PostType model (16 tests)
|
|
117
|
+
├── controllers/ # Controller integration tests
|
|
118
|
+
├── routing/ # Routing DSL tests
|
|
119
|
+
├── generators/ # Generator tests
|
|
120
|
+
├── configuration/ # Configuration tests
|
|
121
|
+
└── tasks/ # Rake task tests
|
|
122
|
+
.github/workflows/ # CI/CD pipeline (runs rake: test + standard)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Test Dummy App
|
|
126
|
+
|
|
127
|
+
Integration tests run against a minimal Rails app in `test/dummy/`:
|
|
128
|
+
- Provides real Rails environment for testing migrations, controllers, routes, views
|
|
129
|
+
- Committed to git (excluding tmp/, log/, etc.)
|
|
130
|
+
- Database schema is managed via migrations in `test/dummy/db/migrate/`
|
|
131
|
+
|
|
132
|
+
## Requirements
|
|
133
|
+
|
|
134
|
+
- Ruby >= 3.2.0
|
|
135
|
+
- Rails >= 8.0
|
|
136
|
+
- Bundler
|
|
137
|
+
|
|
138
|
+
## Development Notes
|
|
139
|
+
|
|
140
|
+
- This gem uses **Standard** for Ruby linting (configured in `.standard.yml`)
|
|
141
|
+
- Tests use **Minitest** framework
|
|
142
|
+
- CI runs on GitHub Actions (`.github/workflows/main.yml`) and executes `bundle exec rake`
|
|
143
|
+
|
|
144
|
+
## Current Features (Implemented)
|
|
145
|
+
|
|
146
|
+
**Milestone 1 - Post Model Behavior:**
|
|
147
|
+
- `acts_as_bunko_post` concern with scopes (`.published`, `.draft`, `.scheduled`, `.by_post_type`)
|
|
148
|
+
- Automatic slug generation from titles (URL-safe, unique within post_type)
|
|
149
|
+
- Publishing workflow (auto-sets `published_at` when status changes to "published")
|
|
150
|
+
- Reading time calculation based on word_count
|
|
151
|
+
|
|
152
|
+
**Milestone 2 - Collection Controllers:**
|
|
153
|
+
- `bunko_collection` concern for automatic index/show actions
|
|
154
|
+
- Built-in pagination (configurable per_page, default: 10)
|
|
155
|
+
- Scoped queries (each collection only sees its post_type)
|
|
156
|
+
- Available instance variables: `@posts`, `@post`, `@collection_name`, `@pagination`
|
|
157
|
+
|
|
158
|
+
**Milestone 3 - Installation:**
|
|
159
|
+
- Two-phase installation pattern:
|
|
160
|
+
1. `rails bunko:install` - Creates migrations, models, initializer
|
|
161
|
+
2. `rails bunko:setup` - Generates controllers, views, routes from configuration
|
|
162
|
+
- Install options: `SKIP_SEO=true`, `JSON_CONTENT=true` (passed as environment variables)
|
|
163
|
+
- Configuration-driven: Define post_types in `config/initializers/bunko.rb`
|
|
164
|
+
- Idempotent setup task (safe to re-run when adding new collections)
|
|
165
|
+
- Single-collection setup: `rails bunko:add[name]` for adding individual collections
|
|
166
|
+
- Generated views include:
|
|
167
|
+
- Semantic HTML structure (`<header>`, `<main>`, `<section>`, `<footer>`)
|
|
168
|
+
- Shared partials: `_bunko_nav.html.erb`, `_bunko_styles.html.erb`, `_bunko_footer.html.erb`
|
|
169
|
+
- Basic styling with Pico CSS (https://picocss.com/) - easily removable for custom designs
|
|
170
|
+
- Responsive navigation with collection links
|
|
171
|
+
- Clean, customizable templates
|
|
172
|
+
|
|
173
|
+
**Milestone 4 - Routing Helpers:**
|
|
174
|
+
- `bunko_collection` DSL method extends `ActionDispatch::Routing::Mapper`
|
|
175
|
+
- Automatic hyphenation: underscored slugs (`:case_study`) convert to hyphenated URLs (`/case-study/`)
|
|
176
|
+
- Custom path support: `bunko_collection :case_study, path: "case-studies"`
|
|
177
|
+
- Custom controller support: `bunko_collection :blog, controller: "articles"`
|
|
178
|
+
- Action limiting: `bunko_collection :blog, only: [:index]`
|
|
179
|
+
- Follows Rails idiomatic conventions (like `resources :blog_posts` → `/blog-posts/`)
|
|
180
|
+
|
|
181
|
+
**Smart Collections (v1):**
|
|
182
|
+
- `config.collection` for defining virtual collections
|
|
183
|
+
- Multi-type collections: aggregate posts from multiple PostTypes
|
|
184
|
+
- Optional scopes: filter collections with custom ActiveRecord scopes
|
|
185
|
+
- Smart lookup: controllers check PostType first, then Collection
|
|
186
|
+
- Name conflict validation: prevents PostType/Collection slug collisions
|
|
187
|
+
- Future-ready: designed to support features like authorship, featured flags, taxonomies
|
|
188
|
+
|
|
189
|
+
**Milestone 5 - Post Convenience Methods:**
|
|
190
|
+
- Instance methods for common view patterns (no namespace conflicts)
|
|
191
|
+
- Implementation: Methods added directly to PostMethods concern (not view helpers)
|
|
192
|
+
- Avoids namespace conflicts - `post.excerpt` instead of `bunko_excerpt(post)`
|
|
193
|
+
- Works identically in index loops and show views
|
|
194
|
+
- No helper prefix needed
|
|
195
|
+
- Methods:
|
|
196
|
+
- `post.excerpt(length:, omission:)` - Smart content truncation with HTML stripping
|
|
197
|
+
- `post.published_date(format)` - Locale-aware date formatting via I18n.l
|
|
198
|
+
- `post.reading_time_text` - Returns "X min read" string
|
|
199
|
+
|
|
200
|
+
**Sample Data Generator:**
|
|
201
|
+
- `rails bunko:sample_data` - Generate realistic sample posts for all configured post types
|
|
202
|
+
- Configurable options:
|
|
203
|
+
- `COUNT=N` - Number of posts per post type (default: 100)
|
|
204
|
+
- `FORMAT=plain|markdown|html` - Content format (default: plain)
|
|
205
|
+
- `MIN_WORDS=N` and `MAX_WORDS=N` - Word count range (default: 200-2000)
|
|
206
|
+
- `CLEAR=true` - Clear existing posts before generating
|
|
207
|
+
- Generated posts include:
|
|
208
|
+
- Realistic titles based on post type
|
|
209
|
+
- Unique slugs
|
|
210
|
+
- Meta descriptions and title tags
|
|
211
|
+
- Published dates (90% past, 10% scheduled for future)
|
|
212
|
+
- Automatic word count calculation
|
|
213
|
+
- Formatted content with headings, paragraphs, lists, blockquotes, and links
|
|
214
|
+
- HTML format includes semantic tags and optional CSS classes for styling
|
|
215
|
+
- Markdown format includes full Markdown syntax
|
|
216
|
+
- Useful for testing, demos, and development
|
|
217
|
+
|
|
218
|
+
**Static Pages (Milestone 6):**
|
|
219
|
+
- `bunko_page` routing DSL for standalone pages (e.g., About, Contact, Privacy)
|
|
220
|
+
- Single shared `PagesController` for all pages (no per-page controller generation)
|
|
221
|
+
- Smart view resolution: checks for custom templates (e.g., `pages/about.html.erb`) or falls back to default
|
|
222
|
+
- Opt-out configuration: `config.allow_static_pages = false`
|
|
223
|
+
- Reserved "pages" post_type namespace with validation
|
|
224
|
+
- Auto-generated during `rails bunko:setup` if enabled (default: true)
|
|
225
|
+
- Supports custom paths and controllers: `bunko_page :about, path: "about-us"`
|
|
226
|
+
- Works with namespaces: `namespace :legal do bunko_page :privacy end`
|
|
227
|
+
- Same Post model as collections (one-model architecture maintained)
|
|
228
|
+
|
|
229
|
+
## Development Roadmap
|
|
230
|
+
|
|
231
|
+
See ROADMAP.md for the complete 1.0.0 release plan with specs and milestones.
|
|
232
|
+
|
|
233
|
+
**Current Status:**
|
|
234
|
+
- ✅ Milestone 1: Post Model Behavior - COMPLETED
|
|
235
|
+
- ✅ Milestone 2: Collection Controllers - COMPLETED
|
|
236
|
+
- ✅ Milestone 3: Installation Generator - COMPLETED
|
|
237
|
+
- ✅ Milestone 4: Routing Helpers - COMPLETED
|
|
238
|
+
- ✅ Milestone 5: Post Convenience Methods - COMPLETED
|
|
239
|
+
- ✅ Milestone 6: Static Pages - COMPLETED
|
|
240
|
+
- 🚧 Milestone 7: Configuration - PENDING (core system exists, may need expansion)
|
|
241
|
+
- 🚧 Milestone 8: Documentation - PENDING
|
|
242
|
+
- 🚧 Milestone 9: Release - PENDING
|
|
243
|
+
|
|
244
|
+
## Architecture Principles
|
|
245
|
+
|
|
246
|
+
When implementing features for this gem:
|
|
247
|
+
|
|
248
|
+
1. **Keep it lightweight** - Avoid dependencies unless absolutely necessary
|
|
249
|
+
2. **Stay agnostic** - Don't force opinions on editors, view layers, auth, etc.
|
|
250
|
+
3. **One model architecture** - All content types share the Post model with collection-based routing
|
|
251
|
+
4. **Convention with escape hatches** - Provide sensible defaults but allow customization
|
|
252
|
+
5. **No forced UI** - Helpers over components; let developers control their HTML
|
|
253
|
+
6. **Specs over implementation** - Focus on behavior and outcomes, not prescriptive solutions
|
|
254
|
+
|
|
255
|
+
## Concern Pattern Architecture
|
|
256
|
+
|
|
257
|
+
Bunko follows a consistent concern pattern inspired by gems like Devise and RubyLLM. This pattern:
|
|
258
|
+
- Avoids namespace collisions with user models/controllers
|
|
259
|
+
- Provides clean, extensible organization
|
|
260
|
+
- Follows Rails conventions for `acts_as_*` style macros
|
|
261
|
+
|
|
262
|
+
### Pattern Structure
|
|
263
|
+
|
|
264
|
+
```
|
|
265
|
+
lib/bunko/<layer>/
|
|
266
|
+
acts_as.rb # Public macros (acts_as_bunko_post, bunko_collection)
|
|
267
|
+
*_methods.rb # Internal concern modules (PostMethods, Collection)
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**Key principles:**
|
|
271
|
+
- **Public API:** Users call macros like `acts_as_bunko_post` or `bunko_collection`
|
|
272
|
+
- **Internal modules:** Implementation lives in `Bunko::Models::PostMethods`, `Bunko::Controllers::Collection`
|
|
273
|
+
- **No `::` prefixes needed:** Namespacing avoids collisions with `Post`, `PostType`, etc.
|
|
274
|
+
|
|
275
|
+
### Current Implementations
|
|
276
|
+
|
|
277
|
+
**Models Layer (`lib/bunko/models/`):**
|
|
278
|
+
```ruby
|
|
279
|
+
# acts_as.rb - Defines the acts_as macros
|
|
280
|
+
ActiveRecord::Base.include Bunko::Models::ActsAs
|
|
281
|
+
|
|
282
|
+
# post_methods.rb - Post behavior concern
|
|
283
|
+
module Bunko::Models::PostMethods
|
|
284
|
+
# Associations, validations, scopes, callbacks
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
# post_type_methods.rb - PostType behavior concern
|
|
288
|
+
module Bunko::Models::PostTypeMethods
|
|
289
|
+
# Associations, validations
|
|
290
|
+
end
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
**Controllers Layer (`lib/bunko/controllers/`):**
|
|
294
|
+
```ruby
|
|
295
|
+
# acts_as.rb - Defines bunko_collection macro
|
|
296
|
+
ActionController::Base.include Bunko::Controllers::ActsAs
|
|
297
|
+
|
|
298
|
+
# collection.rb - Collection behavior concern
|
|
299
|
+
module Bunko::Controllers::Collection
|
|
300
|
+
# Index/show actions, pagination, routing
|
|
301
|
+
end
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
**Routing Layer (`lib/bunko/routing/`):**
|
|
305
|
+
```ruby
|
|
306
|
+
# Extends ActionDispatch::Routing::Mapper with bunko_collection DSL
|
|
307
|
+
# Loaded via railtie initializer on :action_controller load
|
|
308
|
+
|
|
309
|
+
# mapper_methods.rb - Routing DSL methods
|
|
310
|
+
module Bunko::Routing::MapperMethods
|
|
311
|
+
def bunko_collection(collection_slug, **options)
|
|
312
|
+
# Creates resourceful routes with slug param
|
|
313
|
+
# Automatically converts underscored slugs to hyphenated URLs
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
**Note on slug storage and URL formatting:**
|
|
319
|
+
- Slugs are stored with underscores in the database (`:case_study`)
|
|
320
|
+
- URLs automatically use hyphens (`/case-study/`)
|
|
321
|
+
- This follows Rails conventions (e.g., `resources :blog_posts` → `/blog-posts/`)
|
|
322
|
+
- Users call routes with underscores: `bunko_collection :case_study`
|
|
323
|
+
- Generated helpers use underscores: `case_study_path(post)`
|
|
324
|
+
|
|
325
|
+
### When to Deviate from This Pattern
|
|
326
|
+
|
|
327
|
+
Use the `Bunko::<Layer>::<Methods>` pattern when:
|
|
328
|
+
- ✅ Adding behavior to existing classes (models, controllers)
|
|
329
|
+
- ✅ Using `include` to mix functionality in
|
|
330
|
+
- ✅ Providing an `acts_as_*` style API
|
|
331
|
+
|
|
332
|
+
Use different patterns for:
|
|
333
|
+
- ❌ Standalone utility classes (use `Bunko::Services::ClassName`)
|
|
334
|
+
- ❌ Rails conventions (validators, helpers, generators - follow Rails patterns)
|
|
335
|
+
- ❌ Service/Query objects (use `Bunko::Services::`, `Bunko::Queries::`)
|
|
336
|
+
- ❌ Presenters/Serializers (use `Bunko::Serializers::`, `Bunko::Presenters::`)
|
|
337
|
+
- ❌ Configuration objects (use `Bunko::Configuration`)
|
|
338
|
+
- ❌ Middleware (use `Bunko::Middleware::`)
|
|
339
|
+
|
|
340
|
+
**Example of future helpers (when needed):**
|
|
341
|
+
```ruby
|
|
342
|
+
# lib/bunko/helpers/post_helper.rb
|
|
343
|
+
module Bunko::Helpers::PostHelper
|
|
344
|
+
def bunko_reading_time(post)
|
|
345
|
+
# Helper logic
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
# Included in views via railtie
|
|
350
|
+
ActionView::Base.include Bunko::Helpers::PostHelper
|
|
351
|
+
```
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Kane
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|