Skip to content

Commit

Permalink
- Add deno support closes #26
Browse files Browse the repository at this point in the history
- Add types
- Fix #34
- Remove the `register` method in favor of https://github.com/riot/register
  • Loading branch information
GianlucaGuarini committed Apr 4, 2022
1 parent 91792a4 commit ec03ebf
Show file tree
Hide file tree
Showing 13 changed files with 2,889 additions and 2,524 deletions.
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
extends: eslint-config-riot

parserOptions:
ecmaVersion: 2018
ecmaVersion: 2021
sourceType: 'module'

globals:
chai: true
chai: true
globalThis: true
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: test

on:
push:
branches: [ main, dev ]
pull_request:
branches: [ main, dev ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 15.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v2
- name: Local Unit Test ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm i
- run: npm test
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Riot.js
Copyright (c) 2019 Gianluca Guarini

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ssr
Riot module to render riot components on the server

[![Build Status][travis-image]][travis-url]
[![Build Status][ci-image]][ci-url]

[![NPM version][npm-version-image]][npm-url]
[![NPM downloads][npm-downloads-image]][npm-url]
Expand All @@ -17,7 +17,7 @@ npm i -S riot @riotjs/compiler @riotjs/ssr

### render - to render only markup

You can simply render your components markup as it follows:
You can simply render your components' markup as it follows:

```js
import MyComponent from './my-component.riot'
Expand Down Expand Up @@ -107,24 +107,6 @@ const {html, css} = fragments('my-component', MyComponent, { some: 'initial prop

It works like the method above but asynchronously

### register - to load riot components in node

If you only want load your components source code in a node environement you just need to register the riot loader hook:

```js
import register from '@riotjs/ssr/register'

import MyComponent from './my-component.riot' // It will fail

// from now on you can load `.riot` tags in node
const unregister = register()

import MyComponent from './my-component.riot' // it works!

// normally you will not need to call this function but if you want you can unhook the riot loader
unregister()
```

### Advanced tips

If you want to render your whole document you can simply pass `html` as name of your root node. For example
Expand Down Expand Up @@ -179,8 +161,9 @@ For example
import MyComponent from './my-component.riot'
import { createRenderer } from '@riotjs/ssr'

const logRendrer = createRenderer(({getHTML, css, dispose, component}) => {
const logRendrer = createRenderer(({getHTML, getCSS, dispose, component}) => {
const html = getHTML()
const css = getCSS()

console.log('Rendering the component: %s', component.name)

Expand Down Expand Up @@ -209,11 +192,29 @@ console.log(global.window, global.document)
domGlobals.clear()
```

### register - to load riot components in node

If you only want to load directly your `riot` components in your node application you might have a look at [`@riotjs/register`](https://github.com/riot/register)
For example:

```js
import register from '@riotjs/register'

import MyComponent from './my-component.riot' // It will fail

// from now on you can load `.riot` tags in node
const unregister = register()

import MyComponent from './my-component.riot' // it works!

// normally you will not need to call this function but if you want you can unhook the riot loader
unregister()
```

#### Caveat

If you are rendering your whole HTML you will not be able to use multiple times the inline `<script>` `<style>` tags.
Of course you can use only once the ones used by Riot.js to customize your components. For example:
Of course, you can use only once the ones used by Riot.js to customize your components. For example:

```riot
<html>
Expand Down Expand Up @@ -250,8 +251,8 @@ Of course you can use only once the ones used by Riot.js to customize your compo
```


[travis-image]:https://img.shields.io/travis/riot/ssr.svg?style=flat-square
[travis-url]:https://travis-ci.org/riot/ssr
[ci-image]:https://img.shields.io/github/workflow/status/riot/ssr/test?style=flat-square
[ci-url]:https://github.com/riot/ssr/actions

[license-image]:http://img.shields.io/badge/license-MIT-000000.svg?style=flat-square
[license-url]:LICENSE
Expand Down
20 changes: 20 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { RiotComponentShell } from 'riot';

export interface RenderingFragments {
html: string
css: string
}

export interface domGlobals {
create: () => void
clear: () => void
}

export const asyncRenderTimeout: number

export function renderAsync<Props extends unknown> (componentName: string, componentShell: RiotComponentShell<Props>, props?: Props): Promise<string>
export function renderAsyncFragments<Props extends unknown> (componentName: string, componentShell: RiotComponentShell<Props>, props?: Props): Promise<RenderingFragments>
export function fragments<Props extends unknown> (componentName: string, componentShell: RiotComponentShell<Props>, props?: Props): RenderingFragments
export function render<Props extends unknown> (componentName: string, componentShell: RiotComponentShell<Props>, props?: Props): string

export default render
Loading

0 comments on commit ec03ebf

Please sign in to comment.