slimview 0.2.0 → 0.2.2
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 +4 -4
- data/README.md +56 -18
- data/bin/slimview +21 -13
- data/lib/slimview/app.rb +34 -0
- data/lib/slimview/server.rb +13 -0
- data/lib/slimview/version.rb +2 -2
- data/lib/slimview.rb +2 -42
- metadata +27 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0aa3ca8b36a79be2250688b865b106e9dd39661f23f356b58a16fb66ee1992f6
|
|
4
|
+
data.tar.gz: a149f31b69c9d97d8cf651499197ece2f59aaf6fe03e16a5039d8c658d89282f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 23067f0a79d9f69fb2846ef9139bbfe45d08db67483baeaddfe6bc197788f3bd5e9b670644485c07c7bcb06e2022ff14d9869353a2e864991dda2e58661f7fdb
|
|
7
|
+
data.tar.gz: 5d3a0cecc4178cb0c060c7fd919a7152243f9893a59b3f40ccde205eb3365581c6f079ade74aecc1fe8588dd184b882826f99f4945e9c0d4abaec11727018b1f
|
data/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# Slimview
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
A lightweight command-line tool and Ruby library for quickly previewing
|
|
6
|
+
[Slim](https://slim-template.github.io/) templates in a local web server
|
|
7
|
+
powered by [Sinatra](https://sinatrarb.com/).
|
|
4
8
|
|
|
5
9
|
## Features
|
|
6
10
|
|
|
@@ -8,6 +12,8 @@ A lightweight command-line tool and Ruby library for quickly previewing [Slim](h
|
|
|
8
12
|
- Minimal setup - just point to a folder and go
|
|
9
13
|
- Automatically reloads templates in development
|
|
10
14
|
- Configurable port and root directory via flags or environment variables
|
|
15
|
+
- Automatically wraps views with `layout.slim` when present
|
|
16
|
+
- Render partial Slim templates via `== slim :other_template`
|
|
11
17
|
|
|
12
18
|
|
|
13
19
|
## Installation
|
|
@@ -22,6 +28,27 @@ Or add it to your `Gemfile`:
|
|
|
22
28
|
gem 'slimview'
|
|
23
29
|
```
|
|
24
30
|
|
|
31
|
+
### Docker
|
|
32
|
+
|
|
33
|
+
Slimview is also available as a docker image:
|
|
34
|
+
|
|
35
|
+
```shell
|
|
36
|
+
docker run --rm -it -v $PWD:/docs -p 3000:3000 dannyben/slimview
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
or as a docker compose service:
|
|
40
|
+
|
|
41
|
+
```yaml
|
|
42
|
+
services:
|
|
43
|
+
web:
|
|
44
|
+
build: .
|
|
45
|
+
image: dannyben/slimview
|
|
46
|
+
volumes: ["./:/docs"]
|
|
47
|
+
ports: ["3000:3000"]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
[View image on Docker Hub](https://hub.docker.com/r/dannyben/slimview)
|
|
51
|
+
|
|
25
52
|
|
|
26
53
|
## Command-Line Usage
|
|
27
54
|
|
|
@@ -31,14 +58,17 @@ $ slimview --help
|
|
|
31
58
|
Usage: slimview [options]
|
|
32
59
|
|
|
33
60
|
Options:
|
|
34
|
-
--port PORT
|
|
35
|
-
--root PATH
|
|
36
|
-
--
|
|
37
|
-
--
|
|
61
|
+
--port PORT Set the port to run the server on (default: 3000)
|
|
62
|
+
--root PATH Set the root templates directory (default: ./templates)
|
|
63
|
+
--assets PATH Set the assets directory (default: <root>/assets)
|
|
64
|
+
--help, -h Show this help message
|
|
65
|
+
--version, -v Print version info
|
|
38
66
|
|
|
39
67
|
Environment Variables:
|
|
40
|
-
SLIMVIEW_PORT
|
|
41
|
-
SLIMVIEW_ROOT
|
|
68
|
+
SLIMVIEW_PORT Set the port
|
|
69
|
+
SLIMVIEW_ROOT Set the root templates directory
|
|
70
|
+
SLIMVIEW_ASSETS Set the assets directory
|
|
71
|
+
|
|
42
72
|
```
|
|
43
73
|
|
|
44
74
|
Example:
|
|
@@ -49,6 +79,12 @@ slimview
|
|
|
49
79
|
|
|
50
80
|
# Serve from another folder on port 8080
|
|
51
81
|
slimview --root app/views --port 8080
|
|
82
|
+
|
|
83
|
+
# Serve with a custom assets directory
|
|
84
|
+
slimview --root app/views --assets public/assets
|
|
85
|
+
|
|
86
|
+
# Use environment variables instead of flags
|
|
87
|
+
SLIMVIEW_ASSETS=public/assets SLIMVIEW_ROOT=app/views slimview
|
|
52
88
|
```
|
|
53
89
|
|
|
54
90
|
## Ruby API Usage
|
|
@@ -59,26 +95,28 @@ You can also use Slimview programmatically from Ruby:
|
|
|
59
95
|
require 'slimview'
|
|
60
96
|
|
|
61
97
|
# Start the server with default port 3000 and default 'templates' root
|
|
62
|
-
Slimview.new.start
|
|
98
|
+
Slimview::Server.new.start
|
|
63
99
|
|
|
64
100
|
# Customize port and templates root
|
|
65
|
-
server = Slimview.new port: 4000, root: 'views/slim'
|
|
101
|
+
server = Slimview::Server.new port: 4000, root: 'views/slim'
|
|
102
|
+
server.start
|
|
103
|
+
|
|
104
|
+
# Override the assets directory
|
|
105
|
+
server = Slimview::Server.new root: 'views/slim', assets: 'public/assets'
|
|
66
106
|
server.start
|
|
67
107
|
|
|
68
108
|
# Pass locals (available as variables inside your Slim templates)
|
|
69
|
-
server = Slimview.new items: ['one', 'two'], title: 'Hello'
|
|
109
|
+
server = Slimview::Server.new items: ['one', 'two'], title: 'Hello'
|
|
70
110
|
server.start
|
|
71
111
|
```
|
|
72
112
|
|
|
73
113
|
|
|
74
114
|
## Notes
|
|
75
115
|
|
|
76
|
-
- Templates are served from the directory specified by `--root`
|
|
77
|
-
|
|
116
|
+
- Templates are served from the directory specified by `--root`
|
|
117
|
+
(or `SLIMVIEW_ROOT`).
|
|
118
|
+
- Static files (images, CSS, JS) can be placed in an `assets/` directory and
|
|
119
|
+
overridden via `--assets` or `SLIMVIEW_ASSETS`.
|
|
78
120
|
- Slim templates are automatically reloaded on each request in development mode.
|
|
79
|
-
- The tool is intended for **local development and previewing**, not for
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
## License
|
|
83
|
-
|
|
84
|
-
MIT License © 2025
|
|
121
|
+
- The tool is intended for **local development and previewing**, not for
|
|
122
|
+
production use.
|
data/bin/slimview
CHANGED
|
@@ -6,14 +6,16 @@ if args.include?('--help') || args.include?('-h')
|
|
|
6
6
|
Usage: slimview [options]
|
|
7
7
|
|
|
8
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
|
-
|
|
12
|
-
|
|
9
|
+
-p, --port PORT Set the port to run the server on (default: 3000)
|
|
10
|
+
-r, --root PATH Set the root templates directory (default: ./templates)
|
|
11
|
+
-a, --assets PATH Set the assets directory (default: <root>/assets)
|
|
12
|
+
-h, --help Show this help message
|
|
13
|
+
-v, --version Print version info
|
|
13
14
|
|
|
14
15
|
Environment Variables:
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
SLIMVIEW_PORT Set the port
|
|
17
|
+
SLIMVIEW_ROOT Set the root templates directory
|
|
18
|
+
SLIMVIEW_ASSETS Set the assets directory
|
|
17
19
|
|
|
18
20
|
HELP
|
|
19
21
|
exit
|
|
@@ -28,16 +30,22 @@ end
|
|
|
28
30
|
|
|
29
31
|
port = nil
|
|
30
32
|
root = nil
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
assets = nil
|
|
34
|
+
|
|
35
|
+
def fetch_arg(args, *flags)
|
|
36
|
+
flags.each do |flag|
|
|
37
|
+
if (index = args.index(flag))
|
|
38
|
+
return args[index + 1]
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
nil
|
|
34
42
|
end
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
port = fetch_arg(args, '--port', '-p')
|
|
45
|
+
root = fetch_arg(args, '--root', '-r')
|
|
46
|
+
assets = fetch_arg(args, '--assets', '-a')
|
|
39
47
|
|
|
40
48
|
port = port.to_i if port
|
|
41
49
|
|
|
42
|
-
server = Slimview.new port: port, root: root
|
|
50
|
+
server = Slimview::Server.new port: port, root: root, assets: assets
|
|
43
51
|
server.start
|
data/lib/slimview/app.rb
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'sinatra/base'
|
|
2
|
+
require 'slim'
|
|
3
|
+
|
|
4
|
+
module Slimview
|
|
5
|
+
class App < Sinatra::Base
|
|
6
|
+
def self.configure!(root:, port:, assets:, locals:)
|
|
7
|
+
Slim::Engine.set_options pretty: true
|
|
8
|
+
|
|
9
|
+
views_path = File.expand_path(root, Dir.pwd)
|
|
10
|
+
|
|
11
|
+
set :bind, '0.0.0.0'
|
|
12
|
+
set :port, port
|
|
13
|
+
set :views, views_path
|
|
14
|
+
set :root, File.expand_path('.')
|
|
15
|
+
set :public_folder, assets
|
|
16
|
+
set :environment, :development
|
|
17
|
+
set :reload_templates, true
|
|
18
|
+
set :protection, except: :host_authorization
|
|
19
|
+
set :host_authorization, permitted_hosts: []
|
|
20
|
+
set :slimview_locals, locals
|
|
21
|
+
|
|
22
|
+
get '/*' do
|
|
23
|
+
page = params[:splat].first
|
|
24
|
+
page = 'index' if page.empty?
|
|
25
|
+
slim_path = File.join(settings.views, "#{page}.slim")
|
|
26
|
+
halt 404, "Template not found: #{page}" unless File.exist?(slim_path)
|
|
27
|
+
|
|
28
|
+
slim page.to_sym, locals: settings.slimview_locals
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
self
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Slimview
|
|
2
|
+
class Server
|
|
3
|
+
def initialize(port: nil, root: nil, assets: nil, **locals)
|
|
4
|
+
@port = port || ENV['SLIMVIEW_PORT']&.to_i || 3000
|
|
5
|
+
@root = root || ENV['SLIMVIEW_ROOT'] || 'templates'
|
|
6
|
+
@assets = assets || ENV['SLIMVIEW_ASSETS'] || "#{@root}/assets"
|
|
7
|
+
@locals = locals
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def start = app.run!
|
|
11
|
+
def app = App.configure!(port: @port, root: @root, assets: @assets, locals: @locals)
|
|
12
|
+
end
|
|
13
|
+
end
|
data/lib/slimview/version.rb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
VERSION = '0.2.
|
|
1
|
+
module Slimview
|
|
2
|
+
VERSION = '0.2.2'
|
|
3
3
|
end
|
data/lib/slimview.rb
CHANGED
|
@@ -1,42 +1,2 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require '
|
|
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
|
|
1
|
+
require 'slimview/server'
|
|
2
|
+
require 'slimview/app'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: slimview
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Danny Ben Shitrit
|
|
@@ -10,19 +10,33 @@ cert_chain: []
|
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
|
-
name:
|
|
13
|
+
name: puma
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '
|
|
18
|
+
version: '7.0'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '
|
|
25
|
+
version: '7.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rackup
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '2.2'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '2.2'
|
|
26
40
|
- !ruby/object:Gem::Dependency
|
|
27
41
|
name: sinatra
|
|
28
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -38,33 +52,33 @@ dependencies:
|
|
|
38
52
|
- !ruby/object:Gem::Version
|
|
39
53
|
version: '4.1'
|
|
40
54
|
- !ruby/object:Gem::Dependency
|
|
41
|
-
name:
|
|
55
|
+
name: slim
|
|
42
56
|
requirement: !ruby/object:Gem::Requirement
|
|
43
57
|
requirements:
|
|
44
58
|
- - "~>"
|
|
45
59
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: '
|
|
60
|
+
version: '5.2'
|
|
47
61
|
type: :runtime
|
|
48
62
|
prerelease: false
|
|
49
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
64
|
requirements:
|
|
51
65
|
- - "~>"
|
|
52
66
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: '
|
|
67
|
+
version: '5.2'
|
|
54
68
|
- !ruby/object:Gem::Dependency
|
|
55
|
-
name:
|
|
69
|
+
name: coffee-script
|
|
56
70
|
requirement: !ruby/object:Gem::Requirement
|
|
57
71
|
requirements:
|
|
58
72
|
- - "~>"
|
|
59
73
|
- !ruby/object:Gem::Version
|
|
60
|
-
version: '2.
|
|
74
|
+
version: '2.4'
|
|
61
75
|
type: :runtime
|
|
62
76
|
prerelease: false
|
|
63
77
|
version_requirements: !ruby/object:Gem::Requirement
|
|
64
78
|
requirements:
|
|
65
79
|
- - "~>"
|
|
66
80
|
- !ruby/object:Gem::Version
|
|
67
|
-
version: '2.
|
|
81
|
+
version: '2.4'
|
|
68
82
|
description: Command-line tool and library for quickly previewing Slim templates in
|
|
69
83
|
a local web server
|
|
70
84
|
email: db@dannyben.com
|
|
@@ -76,6 +90,8 @@ files:
|
|
|
76
90
|
- README.md
|
|
77
91
|
- bin/slimview
|
|
78
92
|
- lib/slimview.rb
|
|
93
|
+
- lib/slimview/app.rb
|
|
94
|
+
- lib/slimview/server.rb
|
|
79
95
|
- lib/slimview/version.rb
|
|
80
96
|
homepage: https://github.com/DannyBen/slimview
|
|
81
97
|
licenses:
|
|
@@ -99,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
99
115
|
- !ruby/object:Gem::Version
|
|
100
116
|
version: '0'
|
|
101
117
|
requirements: []
|
|
102
|
-
rubygems_version:
|
|
118
|
+
rubygems_version: 4.0.6
|
|
103
119
|
specification_version: 4
|
|
104
120
|
summary: Instant Slim Template Server
|
|
105
121
|
test_files: []
|