totaljs/framework4

Request to update "default_root"

KangGeunSu opened this issue · 12 comments

I made an example using totaljs(git)/example/authorization.
example.zip

Common fixes

./views/homepage.html

  • <script src="https://cdn.componentator.com/spa.min@17.js"></script>
    -> <script src="/js/spa.min@17.js"></script>

  • <link rel="stylesheet" href="//cdn.componentator.com/spa.min@17.css" />
    -> <link rel="stylesheet" href="/css/spa.min@17.css" />

  • add
    -> <script src="/js/ui.js"></script>
    -> <link rel="stylesheet" href="/css/ui.css" />

File add

./public/js/
-> spa.min@17.js
-> ui.js

./public/css/
-> spa.min@17.css
-> ui.css

Compare two files

example.zip/authorization

-> total4 original

example.zip/authorization_rw

-> node_modules/total4/utils.js

  • const REG_URLEXT = /(https|http|wss|ws|file):\/\/|\/\/[a-z0-9]|[a-z]:|@\{|/i; (Line 96)
    -> const REG_URLEXT = /(https|http|wss|ws|file):\/\/|\/\/[a-z0-9]|[a-z]:/i;

  • return REG_URLEXT.test(text) ? text : ((text[0] === 'h' ? 'href' : 'src') + '="' + CONF.default_root + (text[pos] === '/' ? text.substring(pos + 1) : text)); (Line 2551)
    -> return REG_URLEXT.test(text) ? text : ((text[0] === 'h' ? 'href' : 'src') + '="' + CONF.default_root + (text[pos] === '/' ? text.substring(pos + 1) : text.substring(pos)));

config

name					: Total.js Auth example

default_root				: /total

// IMPORTANT SETTINGS:
cookie		(generate)	: 10
cookie_secret	(generate)  	: 10

Issues

example.zip/authorization

image

-> Call http://localhost:8000/css/spa.min@17.css
-> No "default_root" when calling "js" or "css".

example.zip/authorization_rw

image

-> Call http://localhost:8000/total/css/spa.min@17.css
-> There is a "default_root" when calling "js" or "css".

Please help me to use "default_root"
Thank you

Thank you so much.
Please try it now: $ npm install total4@beta. I have improved the functionality.

Tested after confirmation.

Hmm....

example.zip/authorization_rw

-> node_modules/total4/utils.js
return REG_URLEXT.test(text) ? text : ((text[0] === 'h' ? 'href' : 'src') + '="' + CONF.default_root + (text[pos] === '/' ? text.substring(pos + 1) : text)); (Line 2551)

Can't I just change this part?

return REG_URLEXT.test(text) ? text : ((text[0] === 'h' ? 'href' : 'src') + '="' + CONF.default_root + (text[pos] === '/' ? text.substring(pos + 1) : text));

Because 'text' is appended with 'href or src' at the end.

Sorry for my lack of explanation.

I have changed the functionality to this:

function $urlremap(text) {
	var pos = text[0] === 'h' ? 6 : 5;
	var url = text.substring(pos, text.length - 1);
	return REG_URLEXT.test(url) ? text : ((text[0] === 'h' ? 'href' : 'src') + '="' + CONF.default_root + (text[pos] === '/' ? text.substring(pos + 1) : text));
}

The current functionality is good. text contains the entire value from the src or href attribute with the attribute name. So first, the method parsers url if it's able to be modified. If yes, then then it changes if by adding a root value from the config. If no, then returns unchanged text.

If no, returning unaltered text results in 2 "href or src" due to preceding "((text[0] === 'h' ? 'href' : 'src') + '=".

Can you create a small example with that problem? Just download emptyproject and try to simulate the problem. I need to debug it.

Can't make it right now...

I can't remember what was inappropriate for const REG_URLEXT = /^(https|http|wss|ws|file):\/\/|\/\/[a-z0-9]|[a-z]:|javascript:|#|@\{|'|"|\(/i;...

const REG_URLEXT = /(https|http|wss|ws|file):\/\/|\/\/[a-z0-9]|[a-z]:/i; is possible, is that ok?

With the example above, we will make the best example.

I like flow!!

const REG_URLEXT = /(https|http|wss|ws|file):\/\/|\/\/[a-z0-9]|[a-z]:/i; this is not possible to use because that RegExp rewrites links below:

<a href="javascript:something()">
<a href="#home">
<a href="@{url}">
var str = '<a href="' + str + '">';

and that's not good.

If you have any problematic example, then send me it.

I checked it over the weekend.

I mostly write FLOW.
I wanted it to be "default_root" in "FLOW"

As a result, now seems to be the case.

It seems appropriate to modify the flow in the current state.

I will try more FLOW and reopen in FLOW.

Thank you very much.

How are you planning to do this?

var str = '<image width="150" height="150" xlink:href="{0}img/theme{1}.png" />'.format(url, common.theme || 'white'));

Yes, there was a bug with xlink:href - I forgot on this type of attribute.

Has confirmed
image

you are the best!!

The background didn't work either, so I tried to edit it a bit, but you solved it all at once.

It's really great!

Thank you always