Module: Bunko::Routing::MapperMethods
- Defined in:
- lib/bunko/routing/mapper_methods.rb
Instance Method Summary collapse
-
#bunko_collection(collection_name, **options) ⇒ Object
Defines routes for a Bunko collection.
-
#bunko_page(page_name, **options) ⇒ Object
Defines a route for a standalone Bunko page.
Instance Method Details
#bunko_collection(collection_name, **options) ⇒ Object
Defines routes for a Bunko collection
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bunko/routing/mapper_methods.rb', line 26 def bunko_collection(collection_name, **) # Extract options with defaults custom_path = .delete(:path) controller = .delete(:controller) || collection_name.to_s # Smart detection: Collections (multi-type aggregations) only get index routes # PostTypes get both index and show routes collection_config = Bunko.configuration.find_collection(collection_name.to_s) # Default actions: Collections get [:index], PostTypes get [:index, :show] # Users can override with :only option default_actions = collection_config ? [:index] : [:index, :show] actions = .delete(:only) || default_actions # Resource name must use underscores (for path helpers) # Path can use hyphens (for URLs) if custom_path # User provided custom path - use it for URLs, underscored version for resource name resource_name = custom_path.to_s.tr("-", "_").to_sym path_value = custom_path else # No custom path - use collection_name for resource name, hyphenate for path resource_name = collection_name path_value = collection_name.to_s.dasherize end # Define the routes resources resource_name, controller: controller, path: path_value, only: actions, param: :slug, ** end |
#bunko_page(page_name, **options) ⇒ Object
Defines a route for a standalone Bunko page
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/bunko/routing/mapper_methods.rb', line 80 def bunko_page(page_name, **) # Extract options with defaults custom_path = .delete(:path) controller = .delete(:controller) || "pages" # Convert to underscores for Ruby conventions (route name, helpers) slug = page_name.to_s.underscore # URL path uses hyphens (Rails convention) path_value = custom_path || slug.dasherize # Route name uses underscores for path helpers (e.g., about_path) route_name = slug.to_sym # Define single GET route # Pass hyphenated slug to match Post.slug format in database get path_value, to: "#{controller}#show", defaults: {page: slug.dasherize}, as: route_name end |