[TW5] How to lower case

290 views
Skip to first unread message

jim

unread,
Sep 12, 2014, 4:35:07 AM9/12/14
to tiddl...@googlegroups.com
Hello
I'd need a small macro with no other purpose than putting a specified text to lower/upper case. I am sure this isn't difficult to implement; nevertheless I require your help.

jim

Eric Shulman

unread,
Sep 12, 2014, 4:44:56 AM9/12/14
to tiddl...@googlegroups.com
On Friday, September 12, 2014 1:35:07 AM UTC-7, jim wrote:
I'd need a small macro with no other purpose than putting a specified text to lower/upper case. I am sure this isn't difficult to implement; nevertheless I require your help.

You can achieve this using inline CSS, like this:
@@text-transform: uppercase;test this@@
@@text-transform: lowercase;TEST THIS@@

You can create macros to encapsulate the CSS, like this:
\define lower(text)
@@text-transform: lowercase;$text$@@
\end
\define upper(text)
@@text-transform: uppercase;$text$@@
\end

which you could then use, like this:
<<lower "This TEXT will APPear in ALL LoWeR case">>
<
<upper "This TEXT will APPear in ALL UpPeR case">>

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

YOUR DONATIONS ARE VERY IMPORTANT!
HELP ME TO HELP YOU - MAKE A CONTRIBUTION TO MY "TIP JAR"...

Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:

jim

unread,
Sep 12, 2014, 6:01:11 AM9/12/14
to tiddl...@googlegroups.com
Thank you for your help. Now, it works fine if I transmit plain text. What if I should handle the text variable dynamically:

\define TableHeaders()
<$list filter="[is[current]split:table-headers[,]]" variable="currentField"><th><$set name="currentFieldSet" value=<<currentField>> ><$button class="tc-btn-invisible" set="!!sort-field" setTo=<<lower $(currentFieldSet)$>> > <<currentField>> </$button></$set></th></$list>
\end


\define lower(text)
@@text-transform: lowercase;$text$@@
\end



In the end the sort-field field of the tiddler should contain the <<currentField>> in lower case. I have changed a few times the emplacement of the variable assignement:  I get the definition of the lower macro or true.

(I am working on the Inline Editable Table by Danielo.)

jim

c pa

unread,
Sep 12, 2014, 11:09:07 AM9/12/14
to tiddl...@googlegroups.com
>> In the end the sort-field field of the tiddler should contain the <<currentField>> in lower case.
To do that you need to convert <<currentField>> to lower case before calling the <<TableHeaders>> macro
So you need a macro that does the conversion then calls <<TableHeaders>> Something like the following:
\define lowerTableHeaders()
<$set name="sort-field" setTo=<<lower $(currentField)gt;> >
<<TableHeaders>>
</$set>

\end

jim

unread,
Sep 12, 2014, 12:27:37 PM9/12/14
to tiddl...@googlegroups.com
Thank you c pa!
The problem with this attempt is that sort-field is assigned to in TableHeaders(). This can't be done elsewhere because of currentField being rendered inside TableHeaders. Or am I wrong?

 I think, I misunderstand some basic concept about the variable assignment:

\define TableHeaders()
<$list filter="[is[current]split:table-headers[,]]" variable="currentField"><th><$button class="tc-btn-invisible" set="!!sort-field" setTo=<<lowerSortField text="<<currentField>>">> ><<currentField>></$button></th></$list>

\end

\define lower(text)
@@text-transform: lowercase;$text$@@
\end

\define lowerSortField(text)
<<lower $text$>>
\end


I want lowerSortField() to return the evaluated string. With the code above I get true. Perhaps my macro-nesting is defective?

When I try to transmit the <<currentField>> in a way similar to c pa's proposition by wrapping it in a setWidget, i.e.
\define TableHeaders()
<$list filter="[is[current]split:table-headers[,]]" variable="currentField"><th><$set name="currentFieldSet" value=<<currentField>> ><$button class="tc-btn-invisible" set="!!sort-field" setTo=<<lowerSortField>> ><<currentField>></$button></$set></th></$list>

\end

\define lower(text)
@@text-transform: lowercase;$text$@@
\end

\define lowerSortField()
<<lower $(currentFieldSet)$>>
\end

I get <<lower a>> where a is the the currentField value.

I'll be much obliged for any further help.

jim

c pa

unread,
Sep 14, 2014, 3:30:09 PM9/14/14
to tiddl...@googlegroups.com
Jim,

Well blow me down. I just spent a good half hour trying to make this work with wiki macros and I couldn't. So the answer is to create a javascript macro

title: $:/_my/macros/setlowercase.js
tags: $:/tags/Macro
!!Add field
module-type: macro
Text:
/*\
title: $:/_my/macros/setlowercase.js
type: application/javascript
module-type: macro

Macro to set a text string to lower case
\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

/*
Information about this macro
*/

exports.name = "setlowercase";

exports.params = [
	{name: "title"}
];

/*
Run the macro
*/
exports.run = function(title) {
	return title.toLowerCase();
};

})();

usage:
<<
setlowercase "TextTo Change Case">>

jim

unread,
Sep 14, 2014, 6:02:52 PM9/14/14
to tiddl...@googlegroups.com
First I'd like to thank you. I didn't want my problem to take so much space and I certainly didn't expect this generous help.

I couldn't achieve my goal with your javascript macro, but I feel we are very close:) The problem seems to be again the macro not evaluating correctly a given variable. So I tried to $macrocall your javascript macro, which didn't work at first because your macro definition wasn't in the same tiddler as the call (as it seems to me). I turned to the starting point using simple css (thanks to Eric Shulman):

\define lower(text)
@@text-transform: lowercase;$text$@@
\end

\define lower2()
<$macrocall $name="lower" text=$(setsort)$/>
\end

<$set name="setsort" value="Rand" >
<<lower2>>
</$set>

Everything works fine (resulting in rand in the text field). But as I try to direct the output to a field by the buttonWidget (code down), the last step isn't evaluated anymore (resulting in <$button set="!!somefield" setTo=Rand/> in the somefield field).

<$set name="setsort" value="Rand" >
<$button set="!!somefield" setTo=<
<lower2>>/>
</$set>

What do think about this?

jim

 

Am Freitag, 12. September 2014 10:35:07 UTC+2 schrieb jim:

Stephan Hradek

unread,
Sep 15, 2014, 3:21:08 AM9/15/14
to tiddl...@googlegroups.com
The problem is: You do NOT convert to lowercase! The variable's content is just DISPLAYED in lower case. That's what the CSS is doing.

If you really want to convert the stored text to lowercase, you need a JavaScript macro which can change a field's value.

jim

unread,
Sep 15, 2014, 11:46:46 AM9/15/14
to tiddl...@googlegroups.com
But this can't be the only problem, since replacing the css and using c pa's macro (see above) doesn't change anything. The resulting value of the somefield field is still the non-evaluated macro call. Or wasn't it this macro type you are speaking of?

\define lower2()
<$macrocall $name="setlowercase" title="$(setsort)$"/>

\end

<$set name="setsort" value="Rand" >
<$button set="!!somefield" setTo=<<lower2>>/>
</
$set>

jim

c pa

unread,
Sep 15, 2014, 12:56:39 PM9/15/14
to tiddl...@googlegroups.com
Wow. This was a hard one. The problem seems to be that $button's setto is unable to process javascript macros. So to solve this requires processing the javascript macro using $Set like this:

\define setbutton()
<$button set="Test1!!somefield" setTo="$(setsort)$" >Set</$button>
\end
\define newone(ttext)
<$set name="setsort" value=<<setlowercase "$ttext$">> >
<<setbutton>>
</$set>
\end

<<newone "This IS a TeSt">>

Reply all
Reply to author
Forward
0 new messages