I'm writing the text version of a Rails mailer email (an example.text.erb file) and I'd like it to display for the recipient with clean breaks after an arbitrary number of characters, say 70. Sublime lets you select a number of paragraphs and break them at the ruler or a fixed char point using Edit >> Wrap >> "Wrap Paragraph at Ruler" but this also includes all the erb code that I've put in (so it's counting the <%= link_to example... %> and not the actual link text output).
This makes the resulting text email that gets sent to the recipient uneven and disjointed because the erb code takes up a number of characters unrelated to the length of its text output.
What's the best way to wrap the text in a *.text.erb file with hard line breaks AFTER the erb has run?
Thanks!
It sounds like you're looking to process the text after it's run through ERB. My initial thought is you could 1) create a custom template handler or 2) hack something together to run a file through ERB and then work on the resulting text.
Also of note is the TextHelper#word wrap method which may be of help to you:
http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-word_wrap
Related
When users paste items from MS word, for example numbered list or bullet points Trix leaves the symbols in, but does not use the default stye rules. eg See below. Note the indenting
I am wanting to replace pasted bulletpoints with '<li>' tags since that is how the browser, or just adds the default style rules to the text.
As a workaround I was thinking that using Javascript/coffee script to replace all incidents of '•' to <li> during a paste command using onPaste='' However this is problematic, since the implementation could cause unforeseen effects.
Another way might be to create a regex expression, to remove the sybols and do It JIT while pasting.
Any other suggestions would be welcome in achieving this.
Edit
/\d\.\s+|[a-z]\)\s+|•\s+|[A-Z]\.\s+|[IVX]+\.\s+[•].\s/g
This regex expression can find Numbered list and a simple replace on the pasted string, will allow for the desired results.
I'm hoping that there are some more options for formatting simple emails formatted as text (not HTML) when using a mailer in a Rails app.
By trial and error, I've found that this markup works in the mailer view (i.e. example_mailer_view.text.erb):
This will be regular text.
==
This text will be formatted in the large, standard HTML Header1 format.
==
The space at the left side of this line will cause it to be smaller text.
>The bracket on the left side of this line will cause it to be indented once.
>>This text is indented twice.
>>This text is indented three times.
_Italicized text_
*This text will be bold.*
Multiple returns...
...between these two lines get compressed into just one blank row.
Is there full documentation of all markup options? Do you know of other markup options that are not listed here? It would be great to have heading2, heading3, etc. Thanks!
Simple text emails are, by definition, simple text. They cannot be formatted. There is no bold simple tyext, nor large simple text, nor italicised simple text. If you see them so, it is because your mail agent is choosing to interpret your plain text emails as if they were written in Markdown; but know that users with other user agents will most likely not see them so. The only way to get rich text emails (i.e. formatted emails) in every email agent (apart from text-only agents such as mutt) is to use an HTML body.
I would like to build invoice text base to have following format:
https://gist.github.com/samnang/9d35a8622af5779a9228
But when I try to render as text format from my controller, then I find out it's very to control how it look because those text are dynamic like company name could be short or long. I don't want to other texts move position depend on something else because those format will be sent to print company to match print out paper.
Is there any examples, gems, or suggestions how to build invoice text base?
You are going to have to truncate some fields to fit into the defined tab area. If you allocate 20 characters of description data, then you need to only allow 20 characters on the output your_text[0..19]
I think working in text for this type of work is going to be overly complex, and you should look at converting the output to pdf to have more control. Take a look at https://github.com/prawnpdf/prawn
Here's my wild and whacky psuedo-code. Anyone know how to make this real?
Background:
This dynamic content comes from a ckeditor. And a lot of folks paste Microsoft Word content in it. No worries, if I just call the attribute untouched it loads pretty. But the catch is that I want it to be just 125 characters abbreviated. When I add truncation to it, then all of the Microsoft Word scripts start popping up. Then I added simple_format, and sanitize, and truncate, and even made my controller start spotting out specific variables that MS would make and gsub them out. But there's too many of them, and it seems like an awfully messy way to accomplish this. Thus so! Realizing that by itself, its clean. I thought, why not just slice it. However, the microsoft word text becomes blank but still holds its numbered position in the string. So I came up with this (probably awful) solution below.
It's in three steps.
When the text parses, it doesn't display any of the MSWord junk. But that text still holds a number position in a slice statement. So I want to use a regexp to find the first actual character.
Take that character and find out what its numbered position is in the total string.
Use a slice statement to cut it from.
def about_us_truncated
x = self.about_us.find.first(regExp representing first actual character)
x.charCount = y
self.about_us[y..125]
end
The only other idea i got, is a regex statement that allows it to explicitly slice only actual characters like so :
about_us([a-zA-Z][0..125]) , but that is definately not how it is written.
Here is some sample text of MS Word junk :
≪! [If Gte Mso 9]>≪Xml>≪Br /> ≪O:Office Document Settings>≪Br /> ≪O:Allow Png/>≪Br /> ≪/O:Off...
You haven't provided much information to go off of, but don't be too leery of trying to build this regex on your own before you seek help...
Take your sample text and paste it in Rubular in the test string area and start building your regex. It has a great quick reference at the bottom.
Stumbled across this
http://gist.github.com/139987
it looks like it requires the sanitize gem.
This is technically not a straight answer, but it seems like the best possible one you can find.
In order to prevent MS Word, you should be using CK Editor's built-in MS word sanitizer. This is because writing regex for it can be very complicated and you can very easily break tags in half and destroy your site with it.
What I did as a workaround, is I did a force paste as plain text in the CK Editor.
In my Rails app, I have a lot of data that is declared as text in the migration file. But when I print these attributes/fields out in the view, all the line breaks are lost and I get one large chunk of text. How do I maintain the line breaks?
This is an HTML problem. Its rules state that consecutive whitespace is converted to a single space.
Rails has a simple_format function that wraps blocks of text in tags so you get the separation you want