From 30773c29c1d45b15ec74ca305837a8c2b57f064b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arist=C3=B3teles?= Date: Fri, 22 Nov 2024 08:44:18 -0300 Subject: [PATCH 1/2] docs: update usage docs --- guides/getting-started/readme.md | 44 ++++++++++++++++++++++++-------- guides/response/readme.md | 16 ++---------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/guides/getting-started/readme.md b/guides/getting-started/readme.md index 361d4ed..e938115 100644 --- a/guides/getting-started/readme.md +++ b/guides/getting-started/readme.md @@ -1,16 +1,19 @@ # Getting Started with Lennarb ## Overview + Lennarb is a lightweight, Rack-based web framework for Ruby that emphasizes simplicity and flexibility. It provides a clean DSL for routing, middleware support, and various ways to structure your web applications. ## Installation Add Lennarb to your project's Gemfile: + ```ruby gem 'lennarb' ``` Or install it directly via RubyGems: + ```bash $ gem install lennarb ``` @@ -18,6 +21,7 @@ $ gem install lennarb ## Quick Start ### Basic Application + Create a new file named `config.ru`: ```ruby @@ -34,6 +38,7 @@ run app ``` Start the server: + ```bash $ rackup ``` @@ -43,6 +48,7 @@ Your application will be available at `http://localhost:9292`. ## Application Structure ### Class-Based Applications + For larger applications, you can use a class-based structure: ```ruby @@ -52,7 +58,7 @@ class MyApp < Lennarb res.status = 200 res.html('

Welcome to MyApp!

') end - + post '/users' do |req, res| user = create_user(req.params) res.status = 201 @@ -65,6 +71,7 @@ run MyApp.freeze! ``` ### Instance-Based Applications + For simpler applications or prototypes: ```ruby @@ -82,7 +89,9 @@ run app ## Routing ### Available HTTP Methods + Lennarb supports all standard HTTP methods: + - `get(path, &block)` - `post(path, &block)` - `put(path, &block)` @@ -92,6 +101,7 @@ Lennarb supports all standard HTTP methods: - `options(path, &block)` ### Route Parameters + Routes can include dynamic parameters: ```ruby @@ -99,7 +109,7 @@ class API < Lennarb get '/users/:id' do |req, res| user_id = req.params[:id] user = User.find(user_id) - + res.status = 200 res.json(user.to_json) end @@ -107,6 +117,7 @@ end ``` ### Response Helpers + Lennarb provides convenient response helpers: ```ruby @@ -138,15 +149,15 @@ class App < Lennarb # Built-in Rack middleware use Rack::Logger use Rack::Session::Cookie, secret: 'your_secret' - + # Custom middleware use MyCustomMiddleware, option1: 'value1' - + get '/' do |req, res| # Access middleware features logger = env['rack.logger'] logger.info 'Processing request...' - + res.status = 200 res.text('Hello World!') end @@ -156,10 +167,11 @@ end ## Application Lifecycle ### Initialization + ```ruby class App < Lennarb # Configuration code here - + def initialize super # Custom initialization code @@ -168,6 +180,7 @@ end ``` ### Freezing the Application + Call `freeze!` to finalize your application configuration: ```ruby @@ -177,6 +190,7 @@ run app ``` After freezing: + - No new routes can be added - No new middleware can be added - The application becomes thread-safe @@ -184,6 +198,7 @@ After freezing: ## Development vs Production ### Development + ```ruby # config.ru require './app' @@ -197,6 +212,7 @@ run App.freeze! ``` ### Production + ```ruby # config.ru require './app' @@ -212,6 +228,7 @@ run App.freeze! ## Best Practices 1. **Route Organization** + ```ruby class App < Lennarb # Group related routes together @@ -219,7 +236,7 @@ run App.freeze! get '/api/users' do |req, res| # Handle API request end - + # Web routes get '/web/dashboard' do |req, res| # Handle web request @@ -228,6 +245,7 @@ run App.freeze! ``` 2. **Error Handling** + ```ruby class App < Lennarb get '/protected' do |req, res| @@ -241,6 +259,7 @@ run App.freeze! ``` 3. **Modular Design** + ```ruby # Split large applications into modules class AdminApp < Lennarb @@ -256,30 +275,33 @@ run App.freeze! ## Running Your Application ### Basic Usage + ```bash $ rackup ``` ### With Environment Configuration + ```bash $ RACK_ENV=production rackup -p 3000 ``` ### With Custom Config File + ```bash $ rackup custom_config.ru ``` ## Next Steps -- Explore the [Plugin System](plugins.md) for extending functionality -- Learn about [Middleware Integration](middleware.md) -- Check out [Advanced Routing](routing.md) -- Read the [API Documentation](api.md) +- Explore the Plugin System for extending functionality +- Learn about Middleware Integration +- Check out Advanced Routing ## Support For help and bug reports, please visit: + - GitHub Issues: [lennarb/issues](https://github.com/your-repo/lennarb/issues) - Documentation: [lennarb.github.io](https://your-docs-site/lennarb) diff --git a/guides/response/readme.md b/guides/response/readme.md index 24d8873..f41ced7 100644 --- a/guides/response/readme.md +++ b/guides/response/readme.md @@ -32,7 +32,7 @@ end But you can also set your own content type: ```ruby -res.headers['Content-Type'] = 'text/markdown' +res['content-type'] = 'text/markdown' res.write '# Hello World' ``` @@ -55,24 +55,12 @@ JSON example: app.post '/posts' do |req, res| req.params # => { name: 'Lenna' } + name = req.params[:name] res.write({ data: { name: } }.to_json) # This will write to the response body end ``` -## Headers - -You can set headers using the `res.header` method: - -```ruby -# app.rb - -app.get '/' do |req, res| - res['Content-Type'] = 'text/plain' - res.write 'Hello World' -end -``` - ## Status Codes You can set the status code using the `res.status` method: From 57dc987baa4cd6952176080088b89db06ecc8592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arist=C3=B3teles?= Date: Fri, 22 Nov 2024 08:44:40 -0300 Subject: [PATCH 2/2] chore: update GA --- .github/workflows/coverage.yaml | 62 ++++++++++++++-------------- .github/workflows/documentation.yaml | 46 ++++++++++----------- .github/workflows/main.yaml | 16 +++---- .github/workflows/publish.yaml | 44 -------------------- .github/workflows/test.yaml | 34 +++++++-------- 5 files changed, 79 insertions(+), 123 deletions(-) delete mode 100644 .github/workflows/publish.yaml diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 68adbf2..a28c665 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -13,45 +13,45 @@ jobs: test: name: ${{matrix.ruby}} on ${{matrix.os}} runs-on: ${{matrix.os}}-latest - + strategy: matrix: os: - ubuntu - macos - + ruby: - - "3.3" - + - '3.3' + steps: - - uses: actions/checkout@v4 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{matrix.ruby}} - bundler-cache: true - - - name: Run tests - timeout-minutes: 5 - run: bundle exec bake test - - - uses: actions/upload-artifact@v3 - with: - name: coverage-${{matrix.os}}-${{matrix.ruby}} - path: .covered.db - + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{matrix.ruby}} + bundler-cache: true + + - name: Run tests + timeout-minutes: 5 + run: bundle exec bake test + + - uses: actions/upload-artifact@v3 + with: + name: coverage-${{matrix.os}}-${{matrix.ruby}} + path: .covered.db + validate: needs: test runs-on: ubuntu-latest - + steps: - - uses: actions/checkout@v4 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: "3.3" - bundler-cache: true - - - uses: actions/download-artifact@v3 - - - name: Validate coverage - timeout-minutes: 5 - run: bundle exec bake covered:validate --paths */.covered.db \; + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3' + bundler-cache: true + + - uses: actions/download-artifact@v3 + + - name: Validate coverage + timeout-minutes: 5 + run: bundle exec bake covered:validate --paths */.covered.db \; diff --git a/.github/workflows/documentation.yaml b/.github/workflows/documentation.yaml index 4fa6552..b76f458 100644 --- a/.github/workflows/documentation.yaml +++ b/.github/workflows/documentation.yaml @@ -13,7 +13,7 @@ permissions: id-token: write concurrency: - group: "pages" + group: 'pages' cancel-in-progress: true env: @@ -23,34 +23,34 @@ env: jobs: generate: runs-on: ubuntu-latest - + steps: - - uses: actions/checkout@v4 - - - uses: ruby/setup-ruby@v1 - with: - ruby-version: "3.3" - bundler-cache: true - - - name: Installing packages - run: sudo apt-get install wget - - - name: Generate documentation - timeout-minutes: 5 - run: bundle exec bake utopia:project:static --force no - - - name: Upload documentation artifact - uses: actions/upload-pages-artifact@v2 - with: - path: docs - + - uses: actions/checkout@v4 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3' + bundler-cache: true + + - name: Installing packages + run: sudo apt-get install wget + + - name: Generate documentation + timeout-minutes: 5 + run: bundle exec bake utopia:project:static --force no + + - name: Upload documentation artifact + uses: actions/upload-pages-artifact@v2 + with: + path: docs + deploy: runs-on: ubuntu-latest - + environment: name: github-pages url: ${{steps.deployment.outputs.page_url}} - + needs: generate steps: - name: Deploy to GitHub Pages diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 9073bd0..adeb101 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -17,11 +17,11 @@ jobs: - '3.2.2' steps: - - uses: actions/checkout@v4 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - - name: Run the default task - run: bundle exec bake test + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Run the default task + run: bundle exec bake test diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml deleted file mode 100644 index c6649fa..0000000 --- a/.github/workflows/publish.yaml +++ /dev/null @@ -1,44 +0,0 @@ -name: Publish Gem - -on: - push: - branches: - - main - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: 3.2 - bundler-cache: true - - - name: Install bundler - run: gem install bundler - - - name: Install dependencies - run: bundle install - - - name: Build gem - run: gem build lennarb.gemspec - - - name: Set up RubyGems credentials - env: - RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }} - run: | - mkdir -p ~/.gem - echo -e "---\n:rubygems_api_key: $RUBYGEMS_API_KEY" > ~/.gem/credentials - chmod 0600 ~/.gem/credentials - - - name: Push gem to RubyGems - env: - RUBYGEMS_HOST: "https://rubygems.org" - RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }} - run: | - cat ~/.gem/credentials | head -c 50 - ls *.gem - gem push $(ls *.gem) - diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0769a98..92b28e0 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -13,20 +13,20 @@ jobs: name: ${{matrix.ruby}} on ${{matrix.os}} runs-on: ${{matrix.os}}-latest continue-on-error: ${{matrix.experimental}} - + strategy: matrix: os: - ubuntu - macos - + ruby: - - "3.1" - - "3.2" - - "3.3" - + - '3.1' + - '3.2' + - '3.3' + experimental: [false] - + include: - os: ubuntu ruby: truffleruby @@ -37,14 +37,14 @@ jobs: - os: ubuntu ruby: head experimental: true - + steps: - - uses: actions/checkout@v4 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{matrix.ruby}} - bundler-cache: true - - - name: Run tests - timeout-minutes: 10 - run: bundle exec bake test + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{matrix.ruby}} + bundler-cache: true + + - name: Run tests + timeout-minutes: 10 + run: bundle exec bake test