I'm using Redcarpet as markdown tool and coderay for syntax highlighting in my rails app. What I want is a preview of what is being written in markdown format before posting it in database. A far better option is a live preview of what's being written like stackoveflow. I know there are many other options but is there any way to stick with redcarpet and coderay and still having a preview of my post with syntax highlighting? Most of the preview options skip the syntax highlighting portion, they even can't detect codes! At least detecting that portion as a code will do. I just need a preview of my post before publishing it. How can I achieve that? I am not interested in using any WYSIWYG editor either!
Your options are either to stick with Redcarpet and use Ajax or to switch to a javascript based markdown processor like: https://github.com/evilstreak/markdown-js and a javascript based syntax highlighter such as: https://github.com/google/code-prettify
With your current setup you'd have to send the markdown to the server via Ajax, process it with Redcarpet then send it back to the browser and inject it into a preview area. This will be much slower and more taxing on your server when traffic goes up. I wouldn't recommend it.
Switch to the js based markdown processor and syntax highlighter so you can do it all in the browser.
Related
I have just found liquid and watched the Railscasts on it. The video was pretty old but from watching it, it i can see liquid is what im looking for. Problem is I'm not sure if it will work with popular wysiwyg editor gems. I don't really want my users to be using plain input fields to make the templates.
I don't know if the wysiwyg editor has to be special to work with liquid or if liquid can basically work with any wysiwyg editor gem.
Are there recommended wysiwyg editor gems that work well with liquid or if that isn't a thing are there just normal editor gems that work with liquid?
Yes. Please read this blog. You can also use newsly gem to manage your liquid template with wysiwyg editor. I used ckeditor in one of my application. It's quite easy to install.
Basically you will need to parse the content and add your own data. The editor will not automatically figure out the variables and their values. The editor will save the content with tags and later you can parse it with Liquid
Here is an example form Liquid
#template = Liquid::Template.parse("hi {{name}}") # Parses and compiles the template
#template.render('name' => 'tobi') # => "hi topi"
https://github.com/Shopify/liquid#how-to-use-liquid
And here is a blog post on how someone is using a wysiwyg with Liquid
https://customer.io/blog/Email-wysiwyg-editor-inspired-by-jekyll.html
Hope that helps
I have a normal view in html in Rails, containing images and links. How do I turn it to be responsive? (I want it to fit also mobile browser sizes, make it html5)
I know I should use fluid, but what is the full command? Or is there another/better way directly from the text editor?
Rails has limited control on the HTML that comes on to the browse.
Try looking at frameworks like Bootstrap or Foundation.
There are some gems that can help you
Foundation-rails
twitter-bootstrap-rails
There is also a railscast episode on Bootstrap basics.
This has nothing much to do with Rails. Rails is a server side language and responsive templates are frontend (html/css) dependent.
However if you are specifically using bootstrap as many beginners do, you could try : https://github.com/seyhunak/twitter-bootstrap-rails gem for a quick integration of things.
I'm building a simple app with Rails using Markdown for storing content. My question is how to build internal [[wiki]] style links? Either by pre-processing before they get to markdown or some markdown derivative? I release I could probably preprocess using regex, but I'm guessing there are others with ready built solutions.
For example I know Instiki uses both markdown and [[wiki|Wiki]] links and I've looked but couldn't figure out how they're handling it.
Any tips?
If you are using the redcarpet gem you can either use a preprocessor or you can modifiy the generated HTML output.
Have a look at How to extend Redcarpet to support a media library. This article shows how to convert image references to custom HTML and also how to replace boilerplate identifiers with the actual content.
I guess both approaches could be adapted for your specific problem:
The renderer approach directly manipulates the generated HTML code from the markdown code. (This is more elegant as you are not messing with Markdown code)
The preprocess approach manipulates the code by using regular expressions (as you already mentioned) (This is more flexible, but also a little bit messy)
I just installed ckeditor into my rails app. Now i am trying to do is, configure redcloth and ckeditor in a way that, instead of the html source i would like the ckeditor to show the redcloth source ?
Any hints on how would i achieve that ?
If you are using CKEditor just for its toolbar, I mean just just the possibility to be able to use buttons to apply formatting, I think you should not use CKEditor, which is (from what I know) absolutely not made to work with markdown. What you are looking is a markdown editor.
I recently looked for a good markdown editor, and guess what, the best solution I have found is Stackoverflow markdown editor. It is called pagedown
Note that this editor is a lot lighter than something like ckeditor since the actual element in which you are editing your content is just a textarea. You just hook pagedown to it by using javascript. In Ckeditor, you are actually writing your content into an iframe with a contentEditable="true" parameter, and CKEditor is recopying what you are writing into a hidden textarea.
I'm working on an email newsletter using ActionMailer that's associated to our Rails 3.0.7 application. So against all my instincts, I'm using inline styles like mad since that seems to be the only way to do things in html email. I'd also like to keep the color scheme consistent with the website in a DRY fashion.
Is there any way to share SASS color variables between a Rails application and its SCSS files for use in inline styling?
The only way I'm aware you can do this is to add .erb onto your sass files so that they're processed by Rails, then you can use application level constants:
<%= APP_CONFIG[:yourkey] %>
Similar question / more reading
Coding emails is such a heinous task that I try to turn off all the higher thinking regions of my brain that worry about good programming principles every time I have to do it. Unless email is the central part of this project I'd resist letting the constraints there affect the rest of your application design.
Best solution I've found so far is the premailer gem: https://github.com/alexdunae/premailer/
Post-processing your HTML with premailer inlines all the CSS defined in a separate stylesheet, letting you specify whatever you want in a SASS or CSS file.