Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mmatongo/primrose.rb
A weird experiment.
https://github.com/mmatongo/primrose.rb
Last synced: about 2 months ago
JSON representation
A weird experiment.
- Host: GitHub
- URL: https://github.com/mmatongo/primrose.rb
- Owner: mmatongo
- License: mit
- Created: 2023-10-15T21:07:01.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2023-10-21T18:48:20.000Z (about 1 year ago)
- Last Synced: 2024-04-24T01:21:28.384Z (8 months ago)
- Language: Ruby
- Size: 39.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Primrose Framework Documentation
## Overview
Primrose is a Ruby library designed for building component-based web applications. It provides a collection of modules and classes to manage the state, routing, rendering, and event handling for a modern web application. Primrose offers the following key features:
- State Management using `Primrose::Store`
- Component-based UI building blocks via `Primrose::Rose` subclasses
- Routing capabilities with `Primrose::Router`
- Observable state via `Primrose::Observable`
- Built-in helper methods and utility functions
- Template-based rendering with ERB---
## Table of Contents
- [Installation](#installation)
- [Usage](#usage)
- [State Management](#state-management)
- [Routing](#routing)
- [Components](#components)
- [Event Handling](#event-handling)
- [Examples](#examples)
- [Contributing](#contributing)
- [License](#license)---
## Installation
You can install the library by adding it to your `Gemfile`:
```ruby
gem 'primrose', '~> 0.0.1'
```Then run `bundle install` to install the dependency.
---
## Usage
### State Management
```ruby
store = Primrose::Store.new({ counter: 0 })store.dispatch({
type: 'INCREMENT',
updates: {
counter: -> (current_value) { current_value + 1 }
}
})
```### Routing
```ruby
router = Primrose::Router.newrouter.route('/home') { puts "You're at home" }
router.route('/about') { puts "About page" }router.navigate('/home') # Outputs "You're at home"
```### Components
Creating a custom component is easy:
```ruby
class MyComponent < Primrose::Rose
def render
"Hello, world!"
end
end
```### Event Handling
You can attach event handlers to your components:
```ruby
component = MyComponent.new
component.on(:click) { puts 'Component clicked!' }
component.trigger(:click) # Outputs "Component clicked!"
```---
## Examples
Below are some example templates to showcase how components can be structured.
- Button Component:
```erb
<%= @label %>
```- Text Field Component:
```erb
```- Checkbox Component:
```erb
<%= @label %>
```---
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
---
## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.
---
For more detailed usage and full API documentation, please refer to the inline code comments and accompanying documentation.
Feel free to raise an issue for any bugs, feature requests, or questions.
**Note**: This documentation assumes that you are familiar with Ruby and ERB (Embedded Ruby).