Vapor render html from MySQL - html

I'm using vapor framework and created a table with longText type in mysql & store text with html tags in it,
+----+----------------------+
| id | content |
+----+----------------------+
| 1 | <b>title</b>sometext |
+----+----------------------+
now when i show them in leaf, it's shows with html tags like:
<b>title</b>sometext
My Leaf file:
but i want to show like:
title sometext
how can i do this?
thanks

Try something like
<pre class="item-body-text-pre">#raw(post.content)</pre>
You can use #raw(<yourVariableHere>) to insert unescaped text.

Related

Jekyll change element based on how you got to post (click order)

Right now I have a Jekyll site theme that allows users to filter posts by selecting tags.
If they are on the home page, it shows all posts and if they have a tag selected it shows only the posts with that tag.
When selecting a post, a new view appears below the post list and tag list which displays the post content. However when this happens, any filtering inside the Post List element goes away.
TAG1 SELECTED POST FROM TAG1 SELECTED
<URL>/tag/tag1 <URL>/POST
+---------+--------------------+ +---------+--------------------+
| Home | Post List | | Home | Post List |
| - Tag1 | <FILTERED ON TAG1> | ---\ | - Tag1 | <SHOWS ALL POSTS> |
| - Tag2 | | ---/ | - Tag2 |<NO LONGER FILTERED>|
+---------+--------------------+ +---------+--------------------+
| POST CONTENT |
| |
+------------------------------+
I have also been able to change the code so that when selecting a tag, then selecting a post, the Post List shows only posts that also contain that tag. However, with this change, it breaks if on the Home page (no tag) and I click a post; the Post List becomes filtered based on the tag associated with the selected post instead of showing all posts. (Note: For my blog I only ever plan on having one tag per post)
HOME SELECTED POST FROM HOME SELECTED
<URL>/ <URL>/POST
+---------+--------------------+ +---------+--------------------+
| Home | Post List | | Home | Post List |
| - Tag1 | <SHOWS ALL POSTS> | ---\ | - Tag1 | <FILTERED ON TAG1> |
| - Tag2 | | ---/ | - Tag2 | <IS NOW FILTERED> |
+---------+--------------------+ +---------+--------------------+
| POST CONTENT |
| |
+------------------------------+
My question is, is there a way in Jekyll to display a post and change the Post List based on how you got to the post?
For instance, if I am on the Home page (that has no filters), and I click a post from the unfiltered Post List, I would like to view the post while keeping the Post List the same (stay unfiltered showing all posts). In addition to that, however, if I click Tag1 in the tag list then click a post from the now filtered Post List, I would like to view the post while keeping the Post List the same (continue to filter all posts on tag1). See the wireframe below for visual explanation.
Is this at all possible using Jekyll and its corresponding tools (Front Matter, Liquid...)? Or would I require a plugin of some kind?
Any help is greatly appreciated.
Yes, you can do that with Jekyll by using a generator plugin. But I think that this introduces unnecessary complication to your navigation and content duplication.
Other solutions can be to go dynamic server side or use some javascript client side, but this is still useless complications.
********** Home *******************
Last posts * TAGS
* - tag 1
(maybe some pagination) * - tag 2
*
Tag Page
********** Tag : tag 1 *************
Last posts for Tag 1 * TAGS
* - tag 1
(maybe some pagination) * - tag 2
*
Post page
********** Post page ***************
Post content * TAGS
Author, Date, Tag : tag 1 * - tag 1
* - tag 2
Post content *
***************************
Post tagged : tag 1 *
- post 1 *
- ... *
And you're done with a simple solution anybody can understand and with no useless complication.

Ugly, broken table in pdf generated by sphinx latexpdf from rst

need some help with sphinx latexpdf output.
Have an document version csv-table in rst file. In html looks perfect, in pdf terrible.
my table:
.. csv-table::
:header: Version, Date, Description
:widths: 15, 20, 50
34343, 02/04/2015, "| Added *httsdfsdps* support"
3434, 14/11/2014, "| Added *folsdfsdlow* parameter to *hgfhfg*"
34343, 13/05/2014, "| Added *fdsf* parameter to *dfgdfgdfgdfgfdgdfgdfgdf*"
21321, 29/10/2013, "| Added *sdfsdf* parameter to *dfgsgfds*
| Deprecated afsfsdf interface"
312321, 05/03/2013, "| Added *dsfsdfsddsfsd* parameter to *dfgdfgdfgdfgdfgdf*
| Documented *dfgdgd*"
213211, 28/02/2013, "Added *!=* operator in *fghfghfg*"
2132132, 26/02/2013, "Added *dsfsdfsdfsdfsdfsd* in *fghf*"
213219, 07/02/2013, "| Added *jsonhash* event format
| Added *filter* parameter in event connection
| Added *group* and *map* parameter to *nph-muu-sf*"
21321321, 30/01/2013, "| Added *height* parameter in *dfgdfgdfdfg*
| Added *dfgdfgdfgdf* in dfgdfgdfgdf"
HTML
PDF
Table is not full in pdf. And this style with spaces at top, bottom near text in cells. Why latex does not take size from rst?
Can i make it better? How?
Thanks for help!
I know your question has been posted for a while, but in case it is still an issue, and for posterity who may come upon this here is how I fixed this issue in an rst doc of my own. I had the same issue, but using a standard rst table drawn out explicitly like so.
+--------+--------+---------+
|Column 1|Column 2| Column 3|
+========+========+=========+
|Value |Value |Value |
+--------+--------+---------+
And so on with many cells that would show the same behavior of running over the page end. The solution was using the class: longtable argument, and then very carefully indenting the table so that the class was applied. Like so:
.. table:: Table Title
:class: longtable
+--------+--------+---------+
|Column 1|Column 2| Column 3|
+========+========+=========+
|Value |Value |Value |
+--------+--------+---------+
This when rendered in pdf would properly break the table over multiple pages. You should be able to use the same class on a csv table.
that is my solution:
this issue in my .rst document is because my table is not too long. if your table is much longer, it will switch to next pages automatically. i have 20 rows in my table. so i change one row:
+-----------+-----------+
| | |
| | |
| | |
+-----------+-----------+
to
+-----------+-----------+
| | |
+ + +
| | |
+-----------+-----------+
it will not change your table style in pdf, but actually the table become 21 rows. when my table has 30 rows. it switch to next pages automatically. but this way may be a little stupid...
The list-table directory works. Just include the longtable class.
Example:
.. list-table:: Table Name
:widths: 5 30
:header-rows: 1
:align: center
:class: longtable
* - **Column1**
- **Column 2**
* - Row1itemsforcolumn1
- Row1itemsforcolumn2
.
.
.very very long table
.
.
* - Row1itemsforcolumnn
- Row1itemsforcolumnn
This gives a clean-looking PDF output whereby the contents are continued on the next page.
Final Output

EAV how to store additional field value?

I have a EAV structure in DB and tables: attribute(id,parent_id,code,name) and value(id,entity_id,attribute_id,value).
I'm using parent_id to store attribute's list. For example,
id | parent_id | code | name
1 | null | color_id | Color
2 | 1 | null | Red
3 | 1 | null | Blue
4 | 1 | null | Other
Now I need the ability to store different data on select certain item. This may be one or more inputs. For example:
Color:
(o) Red
(o) Blue
(o) Other (please specify) ______________
How to store it? Create additional table or may be store with parent_id pointed to selected element or something else?
id | parent_id | code | name
4 | 1 | null | Other
5 | 4 | other_one | First text value
6 | 4 | other_two | Second text value
Thought a little bit about it... Here's a try to give you an answer to the question "How to store it":
Make sure, that you get partial structure into your concept. Define kind of types, value packages, things which belong together and use XML. Something like the above could loke like:
<settings>
<parent id="1">
<colors>
<color>Red</color> --here you should think of tags to set the meaning of the color...
<color>Red</color>
<color>Other</color> --here you set whatever color you want
</colors>
</parent>
<parent id="2">
-- Your example with the "First text value" gives me this idea:
<colors>
<color meaning="BackColor">Red</color>
<color meaning="BorderColor">Red</color>
<color meaning="First text value">Blue</color>
<color meaning="Second text value">Green</color>
</colors>
</parent>
</settings>
So my suggestion:
Try to define certain types like "FormColor" and let it be like
<FormColor backcolor="Red" forecolor="blue" first_text="green">
--You may add specialities within the FormColor-element
<SpecialColor meaning="SomeSpecialMeaning">Blue</SpecialColor>
</FormColor>
Place these "types" within a parent element. You can easily pick the parent element via id and read its inner XML. There you find everything you need...
With this approach you are as flexible as with your EAV thing, but much better readable, maintainable and better to evaluate.

MySQL. Way to compose query with "LIKE" which will work similar as url regular expression

for example I have table 'urls'
urls:
___________________________________________
| id | href |
+--------+--------------------------------|
| 1 | /a/b/c/d/e/f/g/ |
+--------+--------------------------------|
| 2 | /a/b/g/ |
+--------+--------------------------------|
| 3 | /a/c/g/ |
+--------+--------------------------------|
| 4 | /a/d/g/ |
+--------+--------------------------------|
| 5 | /a.php?code=g |
+--------+--------------------------------|
| N | anyUrlString |
+--------+--------------------------------|
I wanna select urls which have special format, for example (like ROUTE in popular PHP frameworks)
"/a/#anyparam/g"
so: WHERE href LIKE '/a/%/g'
but it also will select row with id 5, 1..
How to compose LIKE statement to I can get only URI enabled values in #anyparam ?
must be something like this /a/[%, but not ('/','?','\')]/g but what exactly?
Thanks for any proposition!
P.S. Do not propose to use regular expression (it don't use indexes)!
Can you use multiple clauses?
LIKE '/a/%/g' AND NOT LIKE '/a/%?%/g' ....
Chain some "exceptions" together, attacking cases that do not match. It's hard to come up with a general case, with your limited sample set. An EXPLAIN will show if Indexes are still in use.
String and pattern taken from your code:
SELECT 1 WHERE '/a.php?code=g' LIKE '/a/%/g'
^ should not give you anything, since the string your testing doesn't end in /g, it ends with =g.
But an often overlooked ability of LIKE is negative character-classes. Unfortunately they are not variable-length, they always only represent 1 character, but you could REPEAT() them:
LIKE '/a/' + REPEAT('[^/?\]', LEN(#someVar)) + '/g'

Concatentate all rows / alt. find using a regex across all rows

I have a table like this:
+----+---------------------------------------------------+
| id | value |
+----+---------------------------------------------------+
| 1 | My favourite website is http://stackoverflow.com/ |
| 2 | This text doesn't have a link! :( |
| 3 | Hi! A link! http://www.google.com/ |
+----+---------------------------------------------------+
But of course with many rows. What I really want is a list of all the URLs in the fields. In reality they are blog posts, so some will have more than one link. I'm only interested in external links (i.e. start with (/http(s)?/) ).
So, my first thought was to perform a SQL query that returns something like:
My favourite website is http://stackoverflow.com/,This text doesn't have a link! :(,Hi! A link! http://www.google.com/
so I can use regex in PHP.
How do I write that query?
Alternatively, it would be great to go straight to list of URLs with SQL, but I suspect that might be too hard due to the multiple links thing.
Any ideas?
use GROUP_CONCAT
SELECT GROUP_CONCAT( value )
FROM tableName
SQLFiddle Demo
OTHER SOURCE
GROUP_CONCAT