automatically arranging HTML content

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Contact:

automatically arranging HTML content

Post by shadowslash » Sun Jun 06, 2010 12:00 am

I made an authoring app for a client.

What the app mainly does is generate HTML code and upload it to the client's website.

I'm almost finished with it except I hit a problem where I can't think up of the correct logic to tackle a certain issue. Image

Here's the thing:
I need to make certain generated codes get distributed to 3 columns of in an HTML page. I know that didn't explain much about what I want to be done so here's a visual representation.
Image
There is an HTML code (template) that I put into a variable tTemplate.
Block 1 is always present in the template.
Block 2 is optionally present depending on a setting of the user.
Block A, Block B and Block C is always present.
Block A is a single line in the template as "[$BLOCK_A$]".
Block B is a single line in the template as "[$BLOCK_B$]".
Block C is a single line in the template as "[$BLOCK_C$]".
Now let's say I have a block of code called "CodeBlock 1".
Let's say I have 9 items similar to "CodeBlock 1".
That would make it 10 CodeBlocks.
I decided I would use the replace command to process it.
Suppose I use the command replace "[$BLOCK_A$]" with "CodeBlock 1" in tTemplate.
This would've easily worked.
But I need to evenly distribute all 10 CodeBlocks onto Block A, Block B and Block C.
An example of how I want the CodeBlocks to be distributed is displayed below.
Image

Now what IF Block 2 from before isn't enabled by the user?
That would result to the middle column to be shorter than the other two.
To resolve that problem, I would need to make the CodeBlocks adjust accordingly to the loss of the Block 2.
An example is shown below if ever Block 2 wasn't present, the CodeBlocks are re-arranged.
Image

If all these is still confusing you, please tell me what more information I can provide to make it clearer for you to understand. Thanks for answering and sorry for not knowing how to tackle this. Image
Parañaque, Philippines
Image
Image

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: automatically arranging HTML content

Post by mwieder » Sun Jun 06, 2010 3:13 am

Well, I *am* still a bit confused... are you trying to put content into an html table? And if so, wouldn't filling the proper <td> and <tr> tags do the trick?

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Contact:

Re: automatically arranging HTML content

Post by shadowslash » Sun Jun 06, 2010 3:22 am

mwieder wrote:Well, I *am* still a bit confused... are you trying to put content into an html table? And if so, wouldn't filling the proper <td> and <tr> tags do the trick?
Um no I don't think so. I'm using the replace command to replace parts of the HTML code in the template.

Let's say I have:

[$BLOCK_A$]

I'm going to Replace [$BLOCK_A$] with:

CodeBlock 1
CodeBlock 2
CodeBlock 3
CodeBlock 4

The HTML codes for each CodeBlock has already been put after a variable, and that variable is the one replacing [$BLOCK_A$].

The only logic I'm missing is how do I make it so that the CodeBlocks get limited to the number of the overall CodeBlocks divided by 3. (For the columns). lol Image
Parañaque, Philippines
Image
Image

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: automatically arranging HTML content

Post by mwieder » Sun Jun 06, 2010 3:45 am

So if I've got this right,

put (TotalNumberOfCodeBlocks + Block1IfPresent + Block2IfPresent) mod 3 into tNumberOfRows

Then column 1 is

Block 1 if present
tNumberOfRows (-1 if block 1 is present) blocks

column 2 is
Block 2 if present
tNumberOfRows (-1 if block 2 is present) blocks starting from tNumberOfRows

column 3 is
everything else

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Contact:

Re: automatically arranging HTML content

Post by shadowslash » Sun Jun 06, 2010 3:56 am

mwieder wrote:So if I've got this right,

put (TotalNumberOfCodeBlocks + Block1IfPresent + Block2IfPresent) mod 3 into tNumberOfRows

Then column 1 is

Block 1 if present
tNumberOfRows (-1 if block 1 is present) blocks

column 2 is
Block 2 if present
tNumberOfRows (-1 if block 2 is present) blocks starting from tNumberOfRows

column 3 is
everything else
Yeah somewhat like that but column 1, 2 and 3 should have evenly distributed blocks including Block1 and Block2 if present.

E.g.:
10 CodeBlocks + Block1 + Block 2 = 12 Blocks all in all

So that should make the template have 4 blocks each since it should be divided to 3 columns... That 's how it should be distributed evenly. If it isn't divisible by 3, it's okay if column 3 is lesser than column 1 and 2 so long as column 1 and 2 contain the same number of blocks.
Parañaque, Philippines
Image
Image

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: automatically arranging HTML content

Post by mwieder » Sun Jun 06, 2010 8:10 am

I meant / 3 instead of mod 3, but nonetheless...

Let's see if I've got the idea (untested pseudocode):

Code: Select all

put the totalNumberOfCodeBlocks into tBlocks
add 1 to tBlocks -- block 1 is always present
if block2IsPresent then
  add 1 to tBlocks
end if

-- now we have the total number of blocks, including block 1 and block 2 if present

put tBlocks / 3 into tRows
if tBlocks mod 3 is not 0 then
  -- we need another row
  add 1 to tRows
end if

-- now we have the number of rows we need.

put 1 &cr into BLOCK_A
repeat with tRow=1 to tRows-1
  put tRow into tNum
  if there is a codeblock ("DB" & tNum) then
    put "CB" & (tNum) & cr after BLOCK_A
  end if
end repeat

-- do column 2
put tRows into tEnd
if block2IsPresent then
  put 2 &cr into BLOCK_A
  subtract 1 from tEnd
end if
repeat with tRow=1 to tEnd
  put tRow + tRows into tNum
  if there is a codeblock ("DB" & tNum) then
    put "CB" & (tNum) & cr after BLOCK_B
  end if
end repeat

-- do column 3
repeat with tRow=1 to tEnd
  put tRow + tRows + tRows into tNum
  if there is a codeblock ("DB" & tNum) then
    put "CB" & (tNum) & cr after BLOCK_C
  end if
end repeat

Post Reply