Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Question about indenting text (Read 9183 times)
Jason Preston
Full Member
*
Offline



Posts: 5

Question about indenting text
Feb 15th, 2010, 3:02pm
 
I am new to Tinderbox and I am starting to play around with exporting.  What I am trying to do is to indent text along with other attributes.  However, when I do this, I get only the first line of text indented.

Below is my template:
Code:
^indent^##################################################
^indent^^title^
^indent^##################################################
^indent^^value( $Text )^

^children("View Case Notes")^
 



And here is the output.  I have used both Nakakoji and HTML view with the same results.

Code:
##################################################
Test Thread
##################################################


	##################################################
	First Note
	##################################################


		##################################################
		 First Note of the Child
		##################################################
		Looks like it is working

		##################################################
		Second Note of the Child
		##################################################
		This is an example of two lines
However, this line does not get indented

	##################################################
	Second Note
	##################################################
 




I have been reading through the forums and other resources but I am not finding what I am looking for.  Most of what I have found relates to either outlines or complex HTML output and I am looking for simple indentation for text.  Any ideas on how to accomplish this?
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Question about indenting text
Reply #1 - Feb 15th, 2010, 3:41pm
 
^indent^ emits as many tabs as the value of the current note's $OutlineDepth. Optionally, you can supply the indent character, e.g. ^indent(*)^ would emit asterisks.

The indent characters are only added to the line of the template in which they are found.

There is no mechanism to do indented folding of long paragraphs of text - but this isn't a code editing environment so it's not surprising.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Question about indenting text
Reply #2 - Feb 15th, 2010, 5:25pm
 
Of course, if exporting to HTML you could simply wrap the indented paragraph(s) in <blockquote> tags or, using css <div class="indent">
Back to top
 
 
WWW   IP Logged
Ioa Petra-ka
Full Member
*
Offline



Posts: 103
Portland, Oregon, USA
Re: Question about indenting text
Reply #3 - Feb 15th, 2010, 5:28pm
 
The only way I can think of doing this is with the UNIX tool, par. I'm not sure if it ships with OS X so you might have install it, but par is a pretty powerful tool for formatting paragraphs. There might be an option for wrapping and indenting lines based on the initial line indent depth. If you attach the par command to HTMLExportCommand, you could get the results you want in one shot.

Par documentation is a nightmare for a non-coder. I just used the setup found in TextMate's Mail bundle:

Code:
PARINIT="rTbgqRw65 B=.,?!_A_a Q=_s>|+" 



Change the number after 'w' to increase or decrease the line width for wrapping. I'm not sure where the best place to put this is, though. Mark, any insight on whether Tinderbox uses shell environment configuration files, like .profile?
Back to top
 
« Last Edit: Feb 15th, 2010, 6:02pm by Ioa Petra-ka »  

Av
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Question about indenting text
Reply #4 - Feb 15th, 2010, 6:48pm
 
par isn't currently installed in Mac OS X.

re shell variables: see man popen (and man sh)
Back to top
 
« Last Edit: Feb 15th, 2010, 6:50pm by Mark Bernstein »  
WWW   IP Logged
Jason Preston
Full Member
*
Offline



Posts: 5

Re: Question about indenting text
Reply #5 - Feb 15th, 2010, 8:07pm
 
Thanks for all the answers and ideas.  I am more of a shell scripting/text person which is why I was originally asking.  
@Mark Anderson
Thanks for the info.  Now that I better understand how Tinderbox works with values I might be able to come up with a solution via a shell script.  I was hoping to do it all within Tinderbox.

One possible feature suggestion.  I see things like paragraph() and randomLine(), and I was wondering if it would be possible to enhance paragraph to get a specific paragraph such as paragraph 5 or a range such as 3-5.  As far as I know it only does a certain number of paragraphs starting with the first one.  I understand that the typical usage of Tinderbox would be to create separate notes but I can see some value in doing this (such as code documentation for example)

@Mark Bernstein
I did try that in my experimentation and I might end up going that route in the end.  

@Amber Vaesca
After I posted it I did more reading about how to use command line tools/scripts.  I haven't had time to play with this but I did come up with some ideas.  One such idea was to format the content outside of Tinderbox and bring it back into a note through actions or rules to create dynamic content.  I don't have a lot of experience with Tinderbox but so far I am enjoying it.  Hopefully tomorrow I will get a chance to experiment with it some more.
Back to top
 
 
  IP Logged
Jason Preston
Full Member
*
Offline



Posts: 5

Re: Question about indenting text
Reply #6 - Feb 16th, 2010, 10:03am
 
Modified Post as I pasted test code that used spaces instead of tabs the first time. (not enough coffee when I did posted earlier)

After taking everyone's ideas and playing with different options, I think I found my solution.  I played with HTMLExportCommand but it only worked during the actual export not in the "HTML View".  When I was viewing the notes nothing looked different but once I exported the file, then it was good.  So then I started playing with actions() and runCommand().  In my template, I do if() statements to check the $OutlineDepth then based on that, I insert padding with the help of perl.  I don't do any hard breaks so long lines will wrap depending on the size of my windows but for now it will work.

Below is my template that I am using for exporting indented text.  Don't forget to create two user attributes called indentPadding and indentedText (a bit of time wasted on my part wondering why it wasn't working)

Note in the following code each line of if() and action() will result in a blank line.  I pasted it this way for readability but when I saved the template I combined the first 7 lines to make the output cleaner.
Template Code:
^if(OutlineDepth=1)^^action($indentPadding="")^ ^endif^
^if(OutlineDepth=2)^^action($indentPadding="\t")^ ^endif^
^if(OutlineDepth=3)^^action($indentPadding="\t\t")^ ^endif^
^if(OutlineDepth=4)^^action($indentPadding="\t\t\t")^ ^endif^
^if(OutlineDepth=5)^^action($indentPadding="\t\t\t\t")^ ^endif^
^if(OutlineDepth=6)^^action($indentPadding="\t\t\t\t\t")^^endif^
^if(OutlineDepth=7)^^action($indentPadding="\t\t\t\t\t\t")^^endif^
^if(OutlineDepth=8)^^action($indentPadding="\t\t\t\t\t\t\t")^^endif^
^if(OutlineDepth=9)^^action($indentPadding="\t\t\t\t\t\t\t\t")^^endif^
^if(OutlineDepth=10)^^action($indentPadding="\t\t\t\t\t\t\t\t\t")^^endif^
^action($indentedText=runCommand("perl -pi -e 's/^/"+$indentPadding+"/'",  $Text))^
^get(indentPadding)^##################################################
^get(indentPadding)^## ^title^
^get(indentPadding)^##################################################
^get(indentedText)^
^get(indentPadding)^##################################################
^get(indentPadding)^## End notes for ^title^
^get(indentPadding)^##################################################
^children("Indent Notes")^
 



Here is the output.
Code:
  
##################################################
## First Note
##################################################

##################################################
## End notes for First Note
##################################################

	##################################################
	## First level of indentation
	##################################################
	This is what it now looks like
	With multiple lines
	All of them indented to an equal space
	##################################################
	## End notes for First level of indentation
	##################################################

		##################################################
		## Second level of indentation
		##################################################
		It will continue for however many if statements that are created
		Modify to suit you outline structure
		##################################################
		## End notes for Second level of indentation
		##################################################



	##################################################
	## Another first level of indentation
	##################################################

	##################################################
	## End notes for Another first level of indentation
	##################################################
 



Thanks again everyone for all the help.  The more I play with Tinderbox, the more I enjoy it.
Back to top
 
« Last Edit: Feb 16th, 2010, 10:57am by Jason Preston »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Question about indenting text
Reply #7 - Feb 16th, 2010, 11:37am
 
Do you need the stored values?  I believe

perl -e 'print "\t" x 10'

gives you 10 tabs**. So we could simply set $indentPadding like so:

^action($indentPadding=runCommand("perl -e '"+'print "\t'+'" x '+($OutlineDepth-1)+"'"))

We've pruned a good few ^if and ^action statements. At, worst, it gives slightly more succinct template and for big exports it might even speed up export a bit.  I've had to hack around the perl string to allow for runCommand taking a "quoted" string as its argument.

Note that the last-used value of $indentedString is actually stored but as the template (re-)calculates it before each export that shouldn't matter.

** I'm no CL export; the idea came from these code examples, via Google.
Back to top
 
« Last Edit: Feb 16th, 2010, 12:43pm by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Jason Preston
Full Member
*
Offline



Posts: 5

Re: Question about indenting text
Reply #8 - Feb 16th, 2010, 12:44pm
 
Brilliant suggestion Mark.  I might do more tweaking later on but here is my complete template for others to reference if they wish.

Code:
^action($indentPadding=runCommand("perl -e '"+'print "\t'+'" x '+($OutlineDepth-1)+"'"))^^action($indentedText=runCommand("perl -pi -e 's/^/"+$indentPadding+"/'",  $Text))^
^get(indentPadding)^##################################################
^get(indentPadding)^## ^title^
^get(indentPadding)^##################################################
^get(indentedText)^
^get(indentPadding)^##################################################
^get(indentPadding)^## End notes for ^title^
^get(indentPadding)^##################################################
^children("Indent All Notes")^
 

Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Question about indenting text
Reply #9 - Feb 16th, 2010, 1:10pm
 
Thanks for sharing.  Noting you're new to TB, you might find this page on TB coding conventions.  There are few hard and fast rules but, as there's a fair degree of string parsing going on with action/export code I figure helps to think like TB does so that both parties guess the same way in cases of ambiguity! In that vein, I'd commend CamelCase attribute names, e.g. IndentedString vs. indentedString (though as you've experienced the latter is perfectly 'legal').

~~~~~
Here are two printf -based CL that could have been used instead of the perl, code is for 10 items (replace stuff in blue with the TB calculation):

printf "%010d"|tr "0" "\t"

printf -vch  "%10s" "";printf "%s\n" "${ch// /\t}"


Back to top
 
« Last Edit: Feb 16th, 2010, 1:33pm by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Jason Preston
Full Member
*
Offline



Posts: 5

Re: Question about indenting text
Reply #10 - Feb 16th, 2010, 2:30pm
 
I just realized that I forgot to answer you question about storing the values.  I do not need to store the values but I couldn't find how to set a temporary variable within the template so I went with an attribute.  Right now, at the end of the template I set both attributes to "" to clean up the attribute setting.  I don't know if this is the best solution.  Ideally a temporary variable that is forgotten after the iteration would be best.  If that is possible I would love to know it.
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Question about indenting text
Reply #11 - Feb 16th, 2010, 4:14pm
 
Yes, you took the right approach as there's no mechanism for variables.  Apart for appearing in the attribute list, there's little extra 'weight' to a few additional attributes. As you're caching $Text, cleaning down the attribute at the end of the cycle as you're doing in a good idea.

TB's action code is capable but does include iteration loops, select statements, etc such as you might find in a full scripting language - though for those like yourself who understand shell tools you can leverage those - as indeed you've already done. The TBX storage medium is XML with the $Text attribute stored in XML & RTF (I believe $Text is headed towards RTF-only to better support the text features fro which users are asking). Attributes do have data types and the type can't be changed after creation.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Ioa Petra-ka
Full Member
*
Offline



Posts: 103
Portland, Oregon, USA
Re: Question about indenting text
Reply #12 - Feb 16th, 2010, 5:27pm
 
One way to have temporary variables, so long as all you need are the storage of strings and compatible types, is to use a special note for the storage of temporary data. In some of the more complex documents, I have a /Library/Config container that stores notes which have global configuration values to test against in Rules and Actions, and so forth. You could conceivably set and retrieve from $Text(/Library/Config/cache) or something. I haven't tried it, but I can't think of any reason why that wouldn't work. I'm pretty sure the entire engine runs sequentially, so you wouldn't have a problem with one note stampeding over the cache of another note.
Back to top
 
 

Av
  IP Logged
Pages: 1
Send Topic Print