Regex Substitution find a link url - hyperlink

I would like to create a Substitution Regex that find a url in a test and give me in the substition like:
text text
text text https://example.com/texttexttext
text text text
and return me a test like this:
/fdu https://example.com/texttexttext

This should capture the URL, without knowing more details of engine I'm not sure how to suggest substitution though.
(http[s]:\/\/[\w_-]+[\w.,#?^=%&:\/~+#-]*[\w#?^=%&\/~+#-])

Related

Embedding variable inside text using Trix

I would like to let users use variable name inside text box with Trix.
Given a trix text-box that let the user write messages to other user, I would like to be able to do something like this:
"Hello %user_name%"
When sending the message the user_name would be changed to whatever is the user_name.
I would except this to be a fairly standard feature but couldn't find mention of it in the documentation or SO.
I have tried doing a simple .gsub on the model.content.body but this is returning and ActionText::RichText who doesn't know what gsub is.
An easy way to mock variables within text contents is to use search and replace, just replace the strings within the action that receives posted contents:
final_message = params[:message].gsub("%user_name%", "John Doe")
Note that gsub is only available for string type.

Slack slash commands - Variable/Parameters

I'm integrating slack with jenkins to use slash commands and want to know if slash commands have variables
What I want to do is something like this;
/this_word_should_be_in_the_url word
and the be able to use word in the URL the slash command will call.
On their page they have something like /weather 94070
Do I have access to the 94070 and somehow set is as a query parameter for the URL.
Is this possible?
Can't find any documentation of this.
Thanks.
Yes. You will have access to the word as per the example that you mentioned.
So for example, if you have the following:
/this_word_should_be_in_the_url word
Then there will be an additional query parameter named text that will contain everything else after the slash command. If you just have one parameter then it should be simple to just trim and use the text query parameter but if you have multiple words and need to split them into something more meaningful, then you might have to use some regex or simple string split function.
It is documented at How do commands work. In this section they have provided the various query parameters that will get passed to your Slash Command External URL. For the weather example, the data posted as per the documentation is:
token=gIkuvaNzQIHg97ATvDxqgjtO
team_id=T0001
team_domain=example
channel_id=C2147483705
channel_name=test
user_id=U2147483697
user_name=Steve
command=/weather
text=94070
response_url=https://hooks.slack.com/commands/1234/5678
Notice the text parameter in the above list.

How can I put a link inside of a text string in HAML?

This should probably be easier than it is. I just want to put a link inside an HTML paragraph element.
%p{class: "answer"}="Please upload your data to this portal in text (tab-separated) format. Download our template #{raw(link_to 'here', '/templates/upload_template.xlsx')} for sample data and a description of each column."
Rails is encoding the tag information. I don't want tags to be encoded. I want them to be tags.
You can use more than one line inside any block, to solve your problem we will have something like this:
%p{class: "answer"}
Please upload your data to this portal in text (tab-separated) format. Download our template
= link_to 'here', '/templates/upload_template.xlsx'
for sample data and a description of each column."
You can use interpolation directly in Haml, and doing this seems to fix the issue in this case.
So instead of doing this:
%p= "Text with #{something_interpolated} in it."
you can just do
%p Text with #{something_interpolated} in it.
i.e. you don’t need the = or the quotes, since you are just adding a single string. You shouldn’t need to use raw either.
(Also, note you can do %p.answer to set the class attribute, which may be cleaner if the value isn’t being set dynamically.)
Why this is being escaped here is a different matter. I would have expected the two cases (%p= "#{foo}" and %p #{foo}) to behave the same way. However, after a bit of research, this behaviour seems to match how Rails behaves with Erb.

Bold part of a url in markdown

I want to bold part of a url written in markdown.
URL: http://google.com
Intended result: http://google.com
In this example, I want to bold the word "google" inside the whole url. Here, I capitalized what I wanted to bold.
Related question: is there a way to prevent urls from turning into links?
I am processing this with a marked.js. I'm looking for something that will work in http://dillinger.io/
===== Part 2 =====
URL: http://google.com
Intended result: http://google.*com*
How do I also bold the .com part in addition to the google part?
This seems to work
[http://**example**.com](http://example.com).
Using http://daringfireball.net/projects/markdown/dingus the above gives the HTML result:
http://<strong>example</strong>.com
That is exactly what you want.
I'm using markdown and jekyll, and the markdown doc says you can't have any formatting between "ticks." I even tried it with a block and the asterisks still print as characters, because you can't put spaces in a URL and the formatting requires spaces to work. Even HTML commands print as characters ().

Attaching parameters to the URL of a Rails route

This is a silly question but weird enough I Googled it, I am sure i had seen it before in Rails guides but now couldn't find it.
I want to attach parameters to my URL.
My initial url is this: "http://localhost:3000/pharmacy/patients"
Now I attach one URL with string concatination in JavaScript and it will be this:
"http://localhost:3000/pharmacy/patients?provider=234"
And still good.
Now I want to attach a second parameter named thera_class and its values are strings with spaces between them like "Nasal Congestion"
If I want to also concatenate that second parameter to it, How would the URL look like?
The way it would look is:
http://localhost:3000/pharmacy/patients?provider=234&thera_class=Nasal Congestion
To be extra strict, spaces are replaced by %20 in the URL:
http://localhost:3000/pharmacy/patients?provider=234&thera_class=Nasal%20Congestion

Resources