slimview 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/README.md +84 -0
- data/bin/slimview +43 -0
- data/lib/slimview/version.rb +3 -0
- data/lib/slimview.rb +42 -0
- metadata +105 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 492f4ca1ae763a6bdeca63357861cbf17816717e5fb7e488845cea73c9162ae7
         | 
| 4 | 
            +
              data.tar.gz: c4ff4d48bd84127875aeb75e95f91b366e7ae5c45ee83b18f86ff11f72ae56b2
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: a642281c5d19fea3be9e5bdce0abb49c2ce503ca361313f3bf8491e05bf9752a8ee343b2ffd455424df3392d23a0583f266fd91ded177313f5cf6f3deb4d05d7
         | 
| 7 | 
            +
              data.tar.gz: 826f6a2e7edf508e2b29252c94d56509e9d6336448cbc9e66a4cae1b92adefe33fa14e347a44c25b936790391c0bdc1eb951214020c8b167a37f335901cb5753
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,84 @@ | |
| 1 | 
            +
            # Slimview
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            A lightweight command-line tool and Ruby library for quickly previewing [Slim](https://slim-template.github.io/) templates in a local web server powered by [Sinatra](https://sinatrarb.com/).
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Features
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            - Instantly preview `.slim` templates in your browser
         | 
| 8 | 
            +
            - Minimal setup - just point to a folder and go
         | 
| 9 | 
            +
            - Automatically reloads templates in development
         | 
| 10 | 
            +
            - Configurable port and root directory via flags or environment variables
         | 
| 11 | 
            +
             | 
| 12 | 
            +
             | 
| 13 | 
            +
            ## Installation
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            ```bash
         | 
| 16 | 
            +
            gem install slimview
         | 
| 17 | 
            +
            ```
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            Or add it to your `Gemfile`:
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            ```ruby
         | 
| 22 | 
            +
            gem 'slimview'
         | 
| 23 | 
            +
            ```
         | 
| 24 | 
            +
             | 
| 25 | 
            +
             | 
| 26 | 
            +
            ## Command-Line Usage
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            ```bash
         | 
| 29 | 
            +
            $ slimview --help
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            Usage: slimview [options]
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            Options:
         | 
| 34 | 
            +
              --port PORT     Set the port to run the server on (default: 3000)
         | 
| 35 | 
            +
              --root PATH     Set the root templates directory (default: ./templates)
         | 
| 36 | 
            +
              --help, -h      Show this help message
         | 
| 37 | 
            +
              --version, -v   Print version info
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            Environment Variables:
         | 
| 40 | 
            +
              SLIMVIEW_PORT   Set the port (default: 3000)
         | 
| 41 | 
            +
              SLIMVIEW_ROOT   Set the root templates directory (default: ./templates)
         | 
| 42 | 
            +
            ```
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            Example:
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            ```bash
         | 
| 47 | 
            +
            # Serve Slim templates from ./templates at http://localhost:3000
         | 
| 48 | 
            +
            slimview
         | 
| 49 | 
            +
             | 
| 50 | 
            +
            # Serve from another folder on port 8080
         | 
| 51 | 
            +
            slimview --root app/views --port 8080
         | 
| 52 | 
            +
            ```
         | 
| 53 | 
            +
             | 
| 54 | 
            +
            ## Ruby API Usage
         | 
| 55 | 
            +
             | 
| 56 | 
            +
            You can also use Slimview programmatically from Ruby:
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            ```ruby
         | 
| 59 | 
            +
            require 'slimview'
         | 
| 60 | 
            +
             | 
| 61 | 
            +
            # Start the server with default port 3000 and default 'templates' root
         | 
| 62 | 
            +
            Slimview.new.start
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            # Customize port and templates root
         | 
| 65 | 
            +
            server = Slimview.new port: 4000, root: 'views/slim'
         | 
| 66 | 
            +
            server.start
         | 
| 67 | 
            +
             | 
| 68 | 
            +
            # Pass locals (available as variables inside your Slim templates)
         | 
| 69 | 
            +
            server = Slimview.new items: ['one', 'two'], title: 'Hello'
         | 
| 70 | 
            +
            server.start
         | 
| 71 | 
            +
            ```
         | 
| 72 | 
            +
             | 
| 73 | 
            +
             | 
| 74 | 
            +
            ## Notes
         | 
| 75 | 
            +
             | 
| 76 | 
            +
            - Templates are served from the directory specified by `--root` (or `SLIMVIEW_ROOT`).
         | 
| 77 | 
            +
            - Static files (images, CSS, JS) can be placed in an `assets/` subfolder.
         | 
| 78 | 
            +
            - Slim templates are automatically reloaded on each request in development mode.
         | 
| 79 | 
            +
            - The tool is intended for **local development and previewing**, not for production use.
         | 
| 80 | 
            +
             | 
| 81 | 
            +
             | 
| 82 | 
            +
            ## License
         | 
| 83 | 
            +
             | 
| 84 | 
            +
            MIT License © 2025
         | 
    
        data/bin/slimview
    ADDED
    
    | @@ -0,0 +1,43 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
            args = ARGV.dup
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            if args.include?('--help') || args.include?('-h')
         | 
| 5 | 
            +
              puts <<~HELP
         | 
| 6 | 
            +
                Usage: slimview [options]
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                Options:
         | 
| 9 | 
            +
                  --port PORT     Set the port to run the server on (default: 3000)
         | 
| 10 | 
            +
                  --root PATH     Set the root templates directory (default: ./templates)
         | 
| 11 | 
            +
                  --help, -h      Show this help message
         | 
| 12 | 
            +
                  --version, -v   Print version info
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                Environment Variables:
         | 
| 15 | 
            +
                  SLIMVIEW_ROOT   Set the root templates directory
         | 
| 16 | 
            +
                  SLIMVIEW_PORT   Set the port
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              HELP
         | 
| 19 | 
            +
              exit
         | 
| 20 | 
            +
            end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            require 'slimview'
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            if args.include?('--version') || args.include?('-v')
         | 
| 25 | 
            +
              puts Slimview::VERSION
         | 
| 26 | 
            +
              exit
         | 
| 27 | 
            +
            end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            port = nil
         | 
| 30 | 
            +
            root = nil
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            if i = args.index '--port'
         | 
| 33 | 
            +
              port = args[i + 1]
         | 
| 34 | 
            +
            end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            if i = args.index '--root'
         | 
| 37 | 
            +
              root = args[i + 1]
         | 
| 38 | 
            +
            end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            port = port.to_i if port
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            server = Slimview.new port: port, root: root
         | 
| 43 | 
            +
            server.start
         | 
    
        data/lib/slimview.rb
    ADDED
    
    | @@ -0,0 +1,42 @@ | |
| 1 | 
            +
            require 'sinatra/base'
         | 
| 2 | 
            +
            require 'slim'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class Slimview
         | 
| 5 | 
            +
              def initialize(port: nil, root: nil, **locals)
         | 
| 6 | 
            +
                @port = port || ENV['SLIMVIEW_PORT']&.to_i || 3000
         | 
| 7 | 
            +
                @root = root || ENV['SLIMVIEW_ROOT'] || 'templates'
         | 
| 8 | 
            +
                @locals = locals
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              def start = app.run!
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            private
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              def app = @app ||= app!
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def app!
         | 
| 18 | 
            +
                root = @root
         | 
| 19 | 
            +
                port = @port
         | 
| 20 | 
            +
                locals = @locals
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                Class.new Sinatra::Base do
         | 
| 23 | 
            +
                  Slim::Engine.set_options pretty: true
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  set :bind, '0.0.0.0'
         | 
| 26 | 
            +
                  set :port, port
         | 
| 27 | 
            +
                  set :views, root
         | 
| 28 | 
            +
                  set :public_folder, File.join(settings.root, 'assets')
         | 
| 29 | 
            +
                  set :environment, :development
         | 
| 30 | 
            +
                  set :reload_templates, true
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  get '/*' do
         | 
| 33 | 
            +
                    page = params[:splat].first
         | 
| 34 | 
            +
                    page = 'index' if page.empty?
         | 
| 35 | 
            +
                    slim_path = File.join settings.views, "#{page}.slim"
         | 
| 36 | 
            +
                    halt 404, "Template not found: #{page}" unless File.exist? slim_path
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                    slim page.to_sym, locals: locals
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,105 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: slimview
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Danny Ben Shitrit
         | 
| 8 | 
            +
            bindir: bin
         | 
| 9 | 
            +
            cert_chain: []
         | 
| 10 | 
            +
            date: 1980-01-02 00:00:00.000000000 Z
         | 
| 11 | 
            +
            dependencies:
         | 
| 12 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 13 | 
            +
              name: slim
         | 
| 14 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 15 | 
            +
                requirements:
         | 
| 16 | 
            +
                - - "~>"
         | 
| 17 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 18 | 
            +
                    version: '5.2'
         | 
| 19 | 
            +
              type: :runtime
         | 
| 20 | 
            +
              prerelease: false
         | 
| 21 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 22 | 
            +
                requirements:
         | 
| 23 | 
            +
                - - "~>"
         | 
| 24 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 25 | 
            +
                    version: '5.2'
         | 
| 26 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 27 | 
            +
              name: sinatra
         | 
| 28 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 29 | 
            +
                requirements:
         | 
| 30 | 
            +
                - - "~>"
         | 
| 31 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            +
                    version: '4.1'
         | 
| 33 | 
            +
              type: :runtime
         | 
| 34 | 
            +
              prerelease: false
         | 
| 35 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 36 | 
            +
                requirements:
         | 
| 37 | 
            +
                - - "~>"
         | 
| 38 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 39 | 
            +
                    version: '4.1'
         | 
| 40 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 41 | 
            +
              name: puma
         | 
| 42 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 43 | 
            +
                requirements:
         | 
| 44 | 
            +
                - - "~>"
         | 
| 45 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 46 | 
            +
                    version: '7.0'
         | 
| 47 | 
            +
              type: :runtime
         | 
| 48 | 
            +
              prerelease: false
         | 
| 49 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 50 | 
            +
                requirements:
         | 
| 51 | 
            +
                - - "~>"
         | 
| 52 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 53 | 
            +
                    version: '7.0'
         | 
| 54 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 55 | 
            +
              name: rackup
         | 
| 56 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 57 | 
            +
                requirements:
         | 
| 58 | 
            +
                - - "~>"
         | 
| 59 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 60 | 
            +
                    version: '2.2'
         | 
| 61 | 
            +
              type: :runtime
         | 
| 62 | 
            +
              prerelease: false
         | 
| 63 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 64 | 
            +
                requirements:
         | 
| 65 | 
            +
                - - "~>"
         | 
| 66 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 67 | 
            +
                    version: '2.2'
         | 
| 68 | 
            +
            description: Command-line tool and library for quickly previewing Slim templates in
         | 
| 69 | 
            +
              a local web server
         | 
| 70 | 
            +
            email: db@dannyben.com
         | 
| 71 | 
            +
            executables:
         | 
| 72 | 
            +
            - slimview
         | 
| 73 | 
            +
            extensions: []
         | 
| 74 | 
            +
            extra_rdoc_files: []
         | 
| 75 | 
            +
            files:
         | 
| 76 | 
            +
            - README.md
         | 
| 77 | 
            +
            - bin/slimview
         | 
| 78 | 
            +
            - lib/slimview.rb
         | 
| 79 | 
            +
            - lib/slimview/version.rb
         | 
| 80 | 
            +
            homepage: https://github.com/DannyBen/slimview
         | 
| 81 | 
            +
            licenses:
         | 
| 82 | 
            +
            - MIT
         | 
| 83 | 
            +
            metadata:
         | 
| 84 | 
            +
              bug_tracker_uri: https://github.com/dannyben/slimview/issues
         | 
| 85 | 
            +
              changelog_uri: https://github.com/dannyben/slimview/blob/master/CHANGELOG.md
         | 
| 86 | 
            +
              source_code_uri: https://github.com/dannyben/slimview
         | 
| 87 | 
            +
              rubygems_mfa_required: 'true'
         | 
| 88 | 
            +
            rdoc_options: []
         | 
| 89 | 
            +
            require_paths:
         | 
| 90 | 
            +
            - lib
         | 
| 91 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 92 | 
            +
              requirements:
         | 
| 93 | 
            +
              - - ">="
         | 
| 94 | 
            +
                - !ruby/object:Gem::Version
         | 
| 95 | 
            +
                  version: '3.2'
         | 
| 96 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 97 | 
            +
              requirements:
         | 
| 98 | 
            +
              - - ">="
         | 
| 99 | 
            +
                - !ruby/object:Gem::Version
         | 
| 100 | 
            +
                  version: '0'
         | 
| 101 | 
            +
            requirements: []
         | 
| 102 | 
            +
            rubygems_version: 3.6.9
         | 
| 103 | 
            +
            specification_version: 4
         | 
| 104 | 
            +
            summary: Instant Slim Template Server
         | 
| 105 | 
            +
            test_files: []
         |