porous 0.3.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87cf02a737a26d181f89e3ee42f73574a30473e490b4ce045d76960e3dbc6fa5
4
- data.tar.gz: 679a28921b7fc66630d2ec21b75543cd7dc4906d3f77230a052ff9fb08ab1281
3
+ metadata.gz: 97c2c2c1012060cf7e94ce3a27576d5d0deeee6f5dff85f60bc3b546ddf124f3
4
+ data.tar.gz: df1fcc99004ba224f1fab40355e958112ae56c512bc11412558c493adbc398eb
5
5
  SHA512:
6
- metadata.gz: 7e25b7156a1e9d10c8d66ea198be3ddb3da0a87aa904519b6fbe0c71006e13d33f5840c051114c7a8e8506ce73f033492fb1bc4089506534759b8bc1a86d18e6
7
- data.tar.gz: 8da9145c152a0d93d0a2d182f3ade0da334dc9bb898a75483675173f341a3ea42e5fcd1bc8e16b5e949e92b283fc1f845f7772c3fd19e193283d5338a8acd557
6
+ metadata.gz: a9ccbf9700c5fcf531c8421357fef48631bfdb0c60a9fb4bb51282847f72b6d8505d2464b0b10587d935aea1b9d3f7c4abc769d39fc316b4910dbb5b0d4acdd2
7
+ data.tar.gz: b49424e0903cd012bd54ddd0c99c219bdb475b6fe81a1e3c8177256f81479bfeaac0e8c285059e06190b7840ce46f8bc26d06110c77be60cf41d85141cfd8f3f
data/CHANGELOG.md CHANGED
@@ -1,6 +1,5 @@
1
1
  ## [Planned]
2
2
 
3
- - Production mode
4
3
  - Data Abstraction Layer / Object Relational Model
5
4
  - Event Model
6
5
  - Plugin / Extension system
@@ -13,6 +12,25 @@
13
12
  - Disk (file)
14
13
  - Databases (SQLite, PostgreSQL)
15
14
 
15
+ ## [Unreleased]
16
+
17
+ ## [0.3.2] - 25 February 2024
18
+
19
+ - Serve static files with Agoo
20
+ - Split Porous JavaScripts from application scripts
21
+
22
+ ## [0.3.1] - 24 February 2024
23
+
24
+ - Production Mode
25
+ - `porous build production`
26
+ - `porous server`
27
+ - Needs `ssl/cert.pem` and `ssl/key.pem`
28
+ - Binds on :80 and :443
29
+ - Development Mode
30
+ - `porous dev`
31
+ - Binds on :9292
32
+ - Serves favicon from `static/favicon.svg`
33
+
16
34
  ## [0.3.0] - 22 February 2024
17
35
 
18
36
  - WebSockets support
data/README.md CHANGED
@@ -42,21 +42,21 @@ Porous is not a framework. You don't build an application with it as a dependenc
42
42
 
43
43
  ## Usage
44
44
 
45
- Porous is still pre-alpha and so is not ready for usage yet, but the general idea is that you would define your application's entities, pages, components and events in Ruby scripts structured in a specific way. Then you would simply run `porous` while pointing it to that folder and it will spin up a Rack-compatible web server for you to use.
45
+ Porous is still pre-alpha and so is not ready for usage yet, but the general idea is that you would define your application's entities, pages, components and events in Ruby scripts structured in a specific way. Then you would simply run `porous server` while pointing it to that folder and it will spin up a Rack-compatible web server for you to use.
46
46
 
47
47
  > ⚠️ Expect any and all APIs to change radically until version 1.0! Hence why it won't be documented or properly tested until things settle to a more stable state.
48
48
 
49
- To start a new Porous project simply `gem install porous` using whichever Ruby environment you want to use (Ruby 3.0+). Then change to that directory and run:
49
+ To start a new Porous project simply `gem install porous` using whichever Ruby environment you want to use (Ruby 3.0+) and then `porous new` with your project name. Then change to that directory and run:
50
50
 
51
- $ porous server
51
+ $ porous dev
52
52
 
53
- By default Porous will run at `localhost:9292`. Now you can edit `pages/home.rb` or add more pages. Files you modify will be hot-reloaded so you can simply open the page in your browser and edit the file. Hot-reloading will be improved once WebSockets support is implemented.
53
+ By default Porous will run at `localhost:9292`. Now you can edit `pages/home.rb` or add more pages. Files you modify will be hot-reloaded, so you can simply open the page in your browser and edit the file.
54
54
 
55
55
  ### Running examples
56
56
 
57
- To test out some example "apps" using Porous you can navigate to the examples folder and in any folder run:
57
+ To test out an example application using Porous you can clone the [Porous website](https://github.com/exastencil/porous.dev) and in that directory:
58
58
 
59
- $ porous server
59
+ $ porous dev
60
60
 
61
61
  ## Development
62
62
 
@@ -18,8 +18,10 @@ module Porous
18
18
  end
19
19
  meta name: 'description', content: props[:description] if props[:description]
20
20
 
21
- script src: '/static/dist/application.js', id: 'application'
21
+ script src: '/porous.js'
22
+ script src: '/app.js'
22
23
  script src: 'https://cdn.tailwindcss.com'
24
+ link rel: 'icon', href: '/favicon.svg'
23
25
  end
24
26
 
25
27
  body class: 'bg-gray-50 dark:bg-gray-900' do
@@ -12,10 +12,10 @@ module Porous
12
12
  true
13
13
  end
14
14
 
15
- desc 'build', 'Build static assets'
16
- def build
17
- empty_directory 'static/dist', verbose: false, force: options[:force]
18
- Porous::Server::Builder.new.build
15
+ desc 'build ENV', 'Build static assets for environment (default: development)'
16
+ def build(env = :development)
17
+ empty_directory 'static', verbose: false, force: options[:force]
18
+ Porous::Server::Builder.new(env.to_sym).build
19
19
  end
20
20
  end
21
21
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Porous
4
+ class CLI < Thor
5
+ check_unknown_options!
6
+
7
+ namespace :dev
8
+
9
+ desc 'dev', 'Starts a Porous development server'
10
+ def dev # rubocop:todo Metrics/MethodLength
11
+ empty_directory 'static/dist', verbose: false, force: options[:force]
12
+
13
+ Agoo::Log.configure(
14
+ dir: '',
15
+ console: true,
16
+ classic: true,
17
+ colorize: true,
18
+ states: {
19
+ INFO: true,
20
+ DEBUG: false,
21
+ connect: false,
22
+ request: true,
23
+ response: false,
24
+ eval: false,
25
+ push: false
26
+ }
27
+ )
28
+
29
+ Agoo::Server.init 9292, 'static', thread_count: 1, root_first: true
30
+ Agoo::Server.use Rack::ContentLength
31
+ Agoo::Server.use Rack::ShowExceptions
32
+
33
+ # Socket Communication
34
+ $socket ||= Porous::Server::Socket.new
35
+ Agoo::Server.handle nil, '/connect', Porous::Server::Connect.new
36
+ # Server-Side Rendering
37
+ Agoo::Server.handle nil, '**', Porous::Server::Application.new
38
+ Agoo::Server.start
39
+ # Live Reload Builder
40
+ Server::Builder.new.build.start
41
+ end
42
+ end
43
+ end
@@ -6,19 +6,7 @@ module Porous
6
6
 
7
7
  namespace :server
8
8
 
9
- desc 'server [OPTIONS]', 'Starts Porous server'
10
- method_option :port,
11
- aliases: :p,
12
- type: :numeric,
13
- default: 9292,
14
- desc: 'The port Porous will listen on'
15
-
16
- method_option :host,
17
- aliases: :h,
18
- type: :string,
19
- default: 'localhost',
20
- desc: 'The host address Porous will bind to'
21
-
9
+ desc 'server [OPTIONS]', 'Starts Porous server in production mode'
22
10
  def server # rubocop:todo Metrics/MethodLength
23
11
  Agoo::Log.configure(dir: '',
24
12
  console: true,
@@ -27,26 +15,30 @@ module Porous
27
15
  states: {
28
16
  INFO: true,
29
17
  DEBUG: false,
30
- connect: false,
31
- request: false,
18
+ connect: true,
19
+ request: true,
32
20
  response: false,
33
- eval: true,
34
- push: true
21
+ eval: false,
22
+ push: false
35
23
  })
36
24
 
37
- Agoo::Server.init 9292, Dir.pwd, thread_count: 1
25
+ Agoo::Server.init(
26
+ 0, 'static',
27
+ root_first: true,
28
+ thread_count: 0,
29
+ ssl_cert: 'ssl/cert.pem',
30
+ ssl_key: 'ssl/key.pem',
31
+ bind: 'https://:443'
32
+ )
38
33
  Agoo::Server.use Rack::ContentLength
39
- Agoo::Server.use Rack::Static, urls: ['/static']
40
- Agoo::Server.use Rack::ShowExceptions
41
34
 
42
35
  # Socket Communication
43
36
  $socket ||= Porous::Server::Socket.new
44
37
  Agoo::Server.handle nil, '/connect', Porous::Server::Connect.new
45
38
  # Server-Side Rendering
46
39
  Agoo::Server.handle nil, '**', Porous::Server::Application.new
40
+
47
41
  Agoo::Server.start
48
- # Live Reload Builder
49
- Server::Builder.new.build.start
50
42
  end
51
43
  end
52
44
  end
@@ -1 +1,3 @@
1
- static/dist
1
+ static/porous.js
2
+ static/app.js
3
+ ssl
@@ -1,7 +1,21 @@
1
1
  # <%= config[:project_name] %>
2
2
 
3
+ ## Development
4
+
3
5
  ```sh
4
- $ porous run
6
+ $ porous dev
5
7
  ```
6
8
 
7
- Go to [http://localhost:8080/](http://localhost:8080/)
9
+ Go to [http://localhost:9292/](http://localhost:9292/)
10
+
11
+ ## Production
12
+
13
+ Place your SSL certificate in `ssl`:
14
+
15
+ - `ssl/cert.pem`
16
+ - `ssl/key.pem`
17
+
18
+ ```sh
19
+ $ porous build production
20
+ $ porous server
21
+ ```
@@ -32,11 +32,7 @@ class Home
32
32
  end
33
33
  a href: 'https://github.com/exastencil/porous', target: '_blank', rel: 'noopener',
34
34
  class: 'flex items-center space-x-2 text-gray-500 dark:text-gray-400' do
35
- svg role: 'img', width: '24', height: '24', class: 'w-5 h-5', viewBox: '0 0 24 24', fill: 'currentColor',
36
- xmlns: 'http://www.w3.org/2000/svg' do
37
- title 'GitHub'
38
- path d: 'M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12'
39
- end
35
+ img class: 'w-8 h-8 text-gray-500', src: '/static/github.svg'
40
36
  span 'View on GitHub'
41
37
  end
42
38
  end
@@ -0,0 +1,4 @@
1
+ <svg role="img" width="24" height="24" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
2
+ <title>GitHub logo</title>
3
+ <path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"></path>
4
+ </svg>
data/lib/porous/cli.rb CHANGED
@@ -12,5 +12,6 @@ require 'rack'
12
12
  require 'rackup/server'
13
13
 
14
14
  require 'porous/cli/build'
15
+ require 'porous/cli/dev'
15
16
  require 'porous/cli/new'
16
17
  require 'porous/cli/server'
@@ -5,22 +5,29 @@ require 'opal/builder_scheduler/sequential'
5
5
  module Porous
6
6
  module Server
7
7
  class Builder
8
- def initialize
8
+ def initialize(environment = :development)
9
+ @environment = environment
9
10
  @build_queue = Queue.new
10
11
  @last_build = nil
11
12
  @latest_change = Dir.glob(File.join('**', '*.rb')).map { |f| File.mtime f }.max
12
13
  end
13
14
 
14
- def build
15
+ def build # rubocop:todo Metrics/AbcSize
15
16
  components = Dir.glob(File.join('**', '*.rb')).map do |relative_path|
16
17
  modified = File.mtime relative_path
17
18
  @latest_change = modified if modified > @latest_change
18
19
  "require '#{relative_path}'"
19
20
  end
20
- build_string = "require 'porous'; #{components.join ";"}".gsub '.rb', ''
21
+ # Porous
22
+ builder = Opal::Builder.new scheduler: Opal::BuilderScheduler::Sequential, cache: false
23
+ builder.build_str "require 'porous'", '(inline)'
24
+ File.binwrite "#{Dir.pwd}/static/porous.js", builder.to_s
25
+ # App
26
+ build_string = "#{components.join ";"}; ".gsub '.rb', ''
27
+ build_string << inject_socket_connection
21
28
  builder = Opal::Builder.new scheduler: Opal::BuilderScheduler::Sequential, cache: false
22
29
  builder.build_str build_string, '(inline)'
23
- File.binwrite "#{Dir.pwd}/static/dist/application.js", builder.to_s
30
+ File.binwrite "#{Dir.pwd}/static/app.js", builder.to_s
24
31
  @last_build = Time.now
25
32
  self
26
33
  end
@@ -42,11 +49,16 @@ module Porous
42
49
  Thread.new { build }.join
43
50
 
44
51
  # Notify clients
45
- $socket.public 'build', @last_build.inspect
52
+ $socket&.public 'build', @last_build.inspect
46
53
  @build_queue.clear
47
54
  end
48
55
  end
49
56
  # rubocop:enable Metrics/AbcSize
57
+
58
+ def inject_socket_connection
59
+ uri = @environment == :production ? 'wss://localhost/connect' : 'ws://localhost:9292/connect'
60
+ "$connection = '#{uri}'; "
61
+ end
50
62
  end
51
63
  end
52
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Porous
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.2'
5
5
  end
data/opal/porous.rb CHANGED
@@ -3,11 +3,22 @@
3
3
  require 'opal'
4
4
  require 'native'
5
5
  require 'promise'
6
- require 'browser/setup/full'
7
-
8
6
  require 'js'
9
7
  require 'console'
10
8
 
9
+ require 'browser/version'
10
+ require 'browser/utils'
11
+ require 'browser/form_data'
12
+ require 'browser/support'
13
+ require 'browser/event'
14
+ require 'browser/window'
15
+ require 'browser/dom'
16
+ require 'browser/delay'
17
+ require 'browser/interval'
18
+ require 'browser/animation_frame'
19
+ require 'browser/socket'
20
+ require 'browser/history'
21
+
11
22
  require 'virtual_dom'
12
23
  require 'virtual_dom/support/browser'
13
24
 
@@ -29,7 +40,7 @@ end
29
40
 
30
41
  $document.ready do
31
42
  Porous::Application.mount_to($document.body)
32
- Browser::Socket.new 'ws://localhost:9292/connect' do
43
+ Browser::Socket.new $connection do
33
44
  on :open do |_e|
34
45
  $console.info 'Connected to server!'
35
46
  end
@@ -38,14 +49,9 @@ $document.ready do
38
49
  channel, content = e.data.split '|'
39
50
  case channel
40
51
  when 'build'
41
- if content == 'started'
42
- $console.log 'New build started…'
43
- else
44
- $console.log 'Reloading scripts…'
45
- $document.location.reload
46
- end
52
+ $document.location.reload unless content == 'started'
47
53
  else
48
- $console.log "Received #{e.data}"
54
+ $console.log e.data
49
55
  end
50
56
  end
51
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: porous
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Exa Stencil
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-22 00:00:00.000000000 Z
11
+ date: 2024-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: agoo
@@ -102,11 +102,13 @@ files:
102
102
  - lib/porous/application.rb
103
103
  - lib/porous/cli.rb
104
104
  - lib/porous/cli/build.rb
105
+ - lib/porous/cli/dev.rb
105
106
  - lib/porous/cli/new.rb
106
107
  - lib/porous/cli/server.rb
107
108
  - lib/porous/cli/template/.gitignore.tt
108
109
  - lib/porous/cli/template/README.md.tt
109
110
  - lib/porous/cli/template/pages/home.rb
111
+ - lib/porous/cli/template/static/github.svg
110
112
  - lib/porous/cli/template/static/hero.png
111
113
  - lib/porous/component.rb
112
114
  - lib/porous/component/class_methods.rb