Help manipulating CSS as a string - SOLVED

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
User avatar
bubblobill
Giant
Posts: 167
Joined: Sun Jan 24, 2010 3:07 pm

Help manipulating CSS as a string - SOLVED

Post by bubblobill »

Hi folks,

I am constructing a set of meta-tools for constructing frames/dialogue boxes/forms/tables/etc. I was doing well until I tried to be clever by making my CSS editable.

My CSS is stored as a string to make inserting an Internal Style Sheet easier.

Code: Select all

[myCSS=["
<style>
#newTable            { background-color: #F0FFFF; color: #FFFFFF }
#newTable, caption   { background-color: #FFFAF0; color: #44444F }
#newTable, th        { background-color: #D0D0D0; color: #444444 }
#newTable, tr        { color: #4B0082 }
#newTable, tr.alt    { background-color: #FFFFF0; color: #8B4513 }
</style>
"]
Maybe I have just been working too long, but I have had a complete brain fail on extracting string bits. I don't want to just stick it all in a TEXTAREA Input.

What I want is to present the user with a form having a Text Input for each class, and each class style like so:

Code: Select all

...snip:
<tr><td>
<input type="text" name="line1.class" value="#newTable"> 
<input type="text" name="line1.style" value="{ color: #AE23AF }">

rinse and repeat
Please help me lazyweb. How do I extract the required parts from the string to use in the input fields? Anyone mentioning regex should do so in the minimum number of syllables.

There are a three restricting conditions;
  • No UDF
  • No trusted functions
  • My ability
Fingers crossed.
Last edited by bubblobill on Sat Jun 21, 2014 8:56 pm, edited 1 time in total.
Bubblobill on the forum.
@Reverend on the MapTool Discord Server

Responsible for less atrocities than most... I do accept responsibility for these though: SmartDoors, Simple d20 Framework - barebones, Drop-in: All 3.5 SRD Monsters, Drop in: Simple Character Editor, Battletech Framework


User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Help manipulating CSS as a string

Post by aliasmask »

You don't have to use regex. Using the list functions and specifying the separator will do the trick as well.

Code: Select all

pseudo-code
eol = decode("%0A")
styleObj = json.fromList(myCSS,eol)
foreach(line,styleObj)
   classIdTags = listGet(line,0,"{")
   cssText = listGet(line,1,"{") //needs error checking for valid line format
  //  loop for each style, class or tag
  // create form text from template and insert respective variable
end foreach
[r: outputForm]
I'm super tired right now, but maybe this will get you started in right direction.

User avatar
bubblobill
Giant
Posts: 167
Joined: Sun Jan 24, 2010 3:07 pm

Aliasmask officially declared "Clever". More news at eleven.

Post by bubblobill »

Dear Mr Mask,

I officially declare you to be rather clever, and not just a little bit cunning.

Here is the functioning code that turns this;
Spoiler
#newTable { background-color: #F0FFFF; color: #FFFFFF } #newTable, caption { background-color: #FFFAF0; color: #44444F } #newTable, th { background-color: #D0D0D0; color: #444444 } #newTable, tr { color: #4B0082 } #newTable, tr.alt { background-color: #FFFFF0; color: #8B4513 }
into this;
Spoiler
#newTable
background-color: #F0FFFF; color: #FFFFFF
#newTable, caption
background-color: #FFFAF0; color: #44444F
#newTable, th
background-color: #D0D0D0; color: #444444
#newTable, tr
color: #4B0082
#newTable, tr.alt
background-color: #FFFFF0; color: #8B4513

Code: Select all

[eol = decode("%0A")]
[styleObj = json.fromList(myCSS,eol)]
[foreach(line,styleObj,"<br>"),code:{
	[classIdTag= listGet(line,0,"{")]
	[styleText = listGet(  listGet(line,1,"{")  ,0,"}")]

}]
I have nested another listGet on styleText in order to exclude the closing brace at line end.

Now all I have to do is remove my <br> and process the result into a form.

Cheers fellas, you have been most excellent and deserving of praise.

Regards,

me
Bubblobill on the forum.
@Reverend on the MapTool Discord Server

Responsible for less atrocities than most... I do accept responsibility for these though: SmartDoors, Simple d20 Framework - barebones, Drop-in: All 3.5 SRD Monsters, Drop in: Simple Character Editor, Battletech Framework

Post Reply

Return to “Macros”