|
| 1 | +# Redmine Wiki Extensions Plugin - AI Coding Guidelines |
| 2 | + |
| 3 | +## Project Architecture |
| 4 | + |
| 5 | +This is a **Redmine plugin** (not a standalone Rails app) that extends wiki functionality with macros, comments, tags, and voting. The plugin follows Redmine's plugin architecture patterns: |
| 6 | + |
| 7 | +- `init.rb` - Plugin registration, permissions, and menu definitions |
| 8 | +- `lib/` - Wiki macros and patches to Redmine core classes |
| 9 | +- `app/` - Standard Rails MVC structure for additional features |
| 10 | +- `db/migrate/` - Database migrations for plugin-specific tables |
| 11 | +- `build-scripts/` - Complex CI/test environment setup scripts |
| 12 | + |
| 13 | +## Key Components |
| 14 | + |
| 15 | +### Wiki Macros (`lib/*_macro.rb`) |
| 16 | +All macros follow this pattern: |
| 17 | +```ruby |
| 18 | +module WikiExtensions[Name]Macro |
| 19 | + Redmine::WikiFormatting::Macros.register do |
| 20 | + desc "Macro description" |
| 21 | + macro :macro_name do |obj, args| |
| 22 | + # Implementation |
| 23 | + end |
| 24 | + end |
| 25 | +end |
| 26 | +``` |
| 27 | + |
| 28 | +**Important macros**: `count`, `wiki`, `tags`, `recent`, `vote`, `project`, `twitter` |
| 29 | + |
| 30 | +### Patches (`lib/*_patch.rb`) |
| 31 | +Extend Redmine core functionality using Rails' `prepend` pattern. Critical patterns: |
| 32 | +- **Controller patches**: Use `after_action` hooks (e.g., `after_action :wiki_extensions_save_tags`) |
| 33 | +- **Method overrides**: Override `render()` and `respond_to()` in WikiController |
| 34 | +- **Module inclusion**: `ActionView::Base.class_eval { include WikiExtensionsHelper }` |
| 35 | + |
| 36 | +Key patches: |
| 37 | +- `wiki_extensions_wiki_controller_patch.rb` - Adds functionality to WikiController |
| 38 | +- `wiki_extensions_formatter_patch.rb` - Extends wiki formatting |
| 39 | +- `wiki_extensions_helper_patch.rb` - Adds helper methods |
| 40 | + |
| 41 | +### Models (`app/models/`) |
| 42 | +Plugin-specific models with Redmine associations: |
| 43 | +- `WikiExtensionsComment` - Hierarchical comments on wiki pages |
| 44 | +- `WikiExtensionsTag` - Tagging system for wiki pages |
| 45 | +- `WikiExtensionsVote` - Voting/rating system |
| 46 | + |
| 47 | +## Development Workflows |
| 48 | + |
| 49 | +### Testing |
| 50 | +- Use `bundle exec rake redmine:plugins:test NAME=redmine_wiki_extensions` |
| 51 | +- Tests require Redmine environment setup via `build-scripts/install.sh` |
| 52 | +- Coverage reports generated in `coverage/` directory |
| 53 | +- Test fixtures in `test/fixtures/` must be copied to Redmine's test/fixtures/ |
| 54 | + |
| 55 | +### Database Changes |
| 56 | +- Always create migrations in `db/migrate/` with sequential numbering |
| 57 | +- Use `rake redmine:plugins:migrate` for deployment |
| 58 | +- Model tables prefixed with `wiki_extensions_` |
| 59 | + |
| 60 | +### Build Process |
| 61 | +The plugin uses a complex CI setup: |
| 62 | +- Matrix builds across Ruby 3.1-3.4 and Redmine 6.0-master |
| 63 | +- Tests against SQLite, MySQL, PostgreSQL |
| 64 | +- Build scripts in `build-scripts/` handle Redmine checkout and plugin setup |
| 65 | +- **Environment variables**: `TESTSPACE`, `PATH_TO_REDMINE`, `PATH_TO_PLUGIN` must be absolute paths |
| 66 | +- Fixtures are automatically copied from `test/fixtures/` to Redmine's test environment |
| 67 | + |
| 68 | +### Git Workflow |
| 69 | +- **All commits must use English commit messages** - Never use Japanese or other languages |
| 70 | +- Follow conventional commit format: "verb + brief description" |
| 71 | +- Examples: "Add macro functionality", "Fix permission check", "Update documentation" |
| 72 | +- Keep commit messages concise (under 50 characters for subject line) |
| 73 | +- All pull requests must target the `develop` branch |
| 74 | + |
| 75 | +### Code Documentation |
| 76 | +- **All source code comments must be written in English** - Never use Japanese or other languages |
| 77 | +- Use clear, concise English for inline comments, method documentation, and code explanations |
| 78 | +- Follow Ruby documentation conventions using YARD format when appropriate |
| 79 | +- Examples of good comments: |
| 80 | + ```ruby |
| 81 | + # Check if the plugin module is enabled for the current project |
| 82 | + return nil unless WikiExtensionsUtil.is_enabled?(@project) if @project |
| 83 | + |
| 84 | + # Register the macro with Redmine's wiki formatting system |
| 85 | + Redmine::WikiFormatting::Macros.register do |
| 86 | + desc "Display page access count with optional reset functionality" |
| 87 | + macro :count do |obj, args| |
| 88 | + # Implementation details... |
| 89 | + end |
| 90 | + end |
| 91 | + ``` |
| 92 | + |
| 93 | +## Coding Patterns |
| 94 | + |
| 95 | +### Plugin Module Enablement |
| 96 | +**CRITICAL**: Always check if plugin is enabled before any functionality: |
| 97 | +```ruby |
| 98 | +return nil unless WikiExtensionsUtil.is_enabled?(@project) if @project |
| 99 | +``` |
| 100 | +This pattern appears in every macro and controller action. The plugin can be disabled per-project. |
| 101 | + |
| 102 | +### Permission Checks |
| 103 | +Layer permission checks after module enablement: |
| 104 | +```ruby |
| 105 | +return nil unless WikiExtensionsUtil.is_enabled?(@project) if @project |
| 106 | +User.current.allowed_to?({controller: 'wiki_extensions', action: 'action'}, @project) |
| 107 | +``` |
| 108 | + |
| 109 | +### Session State Management |
| 110 | +Macros use session storage for stateful behavior (e.g., access counting): |
| 111 | +```ruby |
| 112 | +session[:access_count_table] = Hash.new unless session[:access_count_table] |
| 113 | +unless session[:access_count_table][page.id] |
| 114 | + WikiExtensionsCount.countup(page.id) |
| 115 | + session[:access_count_table][page.id] = 1 |
| 116 | +end |
| 117 | +``` |
| 118 | + |
| 119 | +### View Helpers |
| 120 | +- Complex HTML generation in `lib/wiki_extensions_helper.rb` |
| 121 | +- Tree-like comment display with JavaScript interaction |
| 122 | +- Contextual menus with permission-based visibility |
| 123 | + |
| 124 | +### Internationalization |
| 125 | +- Locale files in `config/locales/` |
| 126 | +- Use `l(:symbol)` for translations |
| 127 | +- Support for 10+ languages |
| 128 | + |
| 129 | +### JavaScript/CSS |
| 130 | +- Assets in `assets/` directory (not Rails standard `app/assets/`) |
| 131 | +- jQuery-based interactions |
| 132 | +- Separate stylesheets for print (`wiki_extensions_print.css`) |
| 133 | + |
| 134 | +## Integration Points |
| 135 | + |
| 136 | +### With Redmine Core |
| 137 | +- Hooks in `lib/wiki_extensions_application_hooks.rb` |
| 138 | +- Menu integration via `menu :project_menu` in `init.rb` |
| 139 | +- Activity provider for comment notifications |
| 140 | +- Email notifications via `WikiExtensionsCommentsMailer` |
| 141 | + |
| 142 | +### Plugin Settings |
| 143 | +- Per-project settings via `WikiExtensionsSettingsController` |
| 144 | +- Settings stored in `wiki_extensions_settings` table |
| 145 | +- Feature toggles for different functionality |
| 146 | + |
| 147 | +## Common Tasks |
| 148 | + |
| 149 | +### Adding New Macro |
| 150 | +1. Create `lib/wiki_extensions_[name]_macro.rb` |
| 151 | +2. Follow macro registration pattern |
| 152 | +3. Add tests in `test/unit/` |
| 153 | +4. Update permissions in `init.rb` if needed |
| 154 | +5. **Always include module enablement check**: `WikiExtensionsUtil.is_enabled?(@project)` |
| 155 | + |
| 156 | +### Adding Model/Feature |
| 157 | +1. Create migration in `db/migrate/` |
| 158 | +2. Add model in `app/models/` with proper associations |
| 159 | +3. Add controller actions if web interface needed |
| 160 | +4. Update permissions and routes |
| 161 | +5. Add project-specific feature toggles via `WikiExtensionsSetting` |
| 162 | + |
| 163 | +### Debugging |
| 164 | +- Plugin works "only on production mode" (per README) |
| 165 | +- Use Rails logger: `Rails.logger.info` |
| 166 | +- Check `WikiExtensionsUtil.is_enabled?` for feature availability |
| 167 | +- Verify per-project settings via `WikiExtensionsSetting.find_or_create(project.id)` |
0 commit comments