Custom fonts with CKeditor and Rails - ruby-on-rails

In my Rails 4.2 app,I am trying to add new fonts to the CKeditor Toolbar, what I did is the following :
As the documentation says to customize ckeditor I added 2 files :
app/assets/javascripts/ckeditor/config.js
app/assets/javascripts/ckeditor/contents.css
in te config.js I have this code :
CKEDITOR.editorConfig = function(config) {
config.contentsCss = 'contents.css';
config.font_names = 'Open Sans;' + config.font_names;
config.toolbar = [
['Styles', 'Format', 'Font', 'FontSize']
];
}
in the contents.css I have this code :
#font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: local('Open Sans'), local('OpenSans'), url(http://fonts.gstatic.com/s/opensans/v10/cJZKeOuBrn4kERxqtaUH3T8E0i7KZn-EPnyo3HZu7kw.woff) format('woff');
}
Here the 'Open Sans' is added to the fonts in the toolbar's drop-down, but when i try to apply the 'Open Sans' font to a text it doesn't work !
For now I get this error in the firebug console :
"NetworkError: 404 Not Found - http://members.lvh.me:3000/posts/assets/contents.css"
I tried to change the above : config.contentsCss = 'contents.css'; to config.contentsCss = '/assets/javascripts/ckeditor/contents.css'; but it still shows the same 404 Not Found error !!
Also I think even if I fix that it will still don't apply the font ! Is here anyone who know the solution ?
Update :
I replaced the config.contentsCss = 'contents.css'; with config.contentsCss = '/assets/ckeditor/contents.css'; and the error disappear, but when I try to apply the font to a text, there is no change !

After a full day of research I finally found a solution which work well for my need, I hope this can help someone in the same situation (so you don't have to struggle like I did )
just add the following code to your app/assets/javascripts/ckeditor/config.js
CKEDITOR.editorConfig = function(config) {
// .....
// .....
// an array of fonts from "google fonts", I listed 3 fonts here
myFonts = ['Architects Daughter', 'Open Sans', 'Dancing Script'];
config.font_names = 'sans serif';
for(var i = 0; i<myFonts.length; i++){
config.font_names = config.font_names+';'+myFonts[i];
myFonts[i] = 'http://fonts.googleapis.com/css?family='+myFonts[i].replace(' ','+');
//assuming you use jquery
$("head").append("<link rel='stylesheet' href='"+ myFonts[i] +"'>");
}
}
just to mention that this solution is founded here : http://ckeditor.com/forums/CKEditor-3.x/CKE-and-Google-Fonts-Api, thanks to 'naveenram'

Related

Bullet points and alphabets are missing when converting html to pdf using jsPDF

I try to convert from html to pdf using jsPDF.
I could not get the pdf as the original html.
ordered list and unordered list bullet points are missing in the pdf file.
ordered-list-in-html
ordered-list-in-pdf
unordered-list-in-html
unordered-list-in-pdf
function BlazorDownloadFile(filename, text) {
let parser = new DOMParser();
let doc = parser.parseFromString(text, "text/html");
console.log(doc.body);
const element = doc.body;
var opt = {
margin: 1,
filename: filename,
html2canvas: { scale: 2 },
jsPDF: { unit: "cm", format: "a4", orientation: "portrait" },
};
// Choose the element that our invoice is rendered in.
html2pdf().set(opt).from(element).save();
}
Please help me to fix this issue.
Here is a workaround for bullet points in scss you can use to overcome this issue:
ul li {
list-style-type: none;
&:before {
content: '• ';
margin-left: -1em;
}
}

Using google spreadsheets with mit2 app inventor

I want to use google spreadsheet with android. I Tried example program. I created new datasheet. I used example script code. I tried mit2 app program. This program is example program. I also used postman.
Postman show me error.
Postman error page.Postman connection error status 200 OK.
Postman error message is:
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico">
<title>ERROR</title>
<style type="text/css" nonce="B6c+P2HTW+vClzlpE+anwg">body {background-color: #fff; margin: 0; padding: 0;}.errorMessage {font-family: Arial,sans-serif; font-size: 12pt; font-weight: bold; line-height: 150%; padding-top: 25px;}</style>
</head>
<body style="margin:20px">
<div>
<img alt="Google Apps Script" src="//ssl.gstatic.com/docs/script/images/logo.png">
</div>
<div style="text-align:center;font-family:monospace;margin:50px auto 0;max-width:600px">TypeError: Cannot read property 'getSheets' of null (line: 15, file: "denandroid")</div>
</body>
</html>
script code is :
function doGet(e) {
return ManageSheet(e);
}
function doPost(e) {
return ManageSheet(e);
}
function ManageSheet(e) {
//READ ALL RECORDS
if ( e.parameter.func == "ReadAll") {
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheets()[0]; // Postman problem line.
var rg = sh.getDataRange().getValues();
var outString = '';
for(var row=0 ; row<rg.length ; ++row){
outString += rg[row].join(',') + '\n';
}
return ContentService.createTextOutput(outString).setMimeType(ContentService.MimeType.TEXT);
}
//DELETE SINGLE RECORD
else if (e.parameter.func == "Delete") {
var record = e.parameter.id;
var ss = SpreadsheetApp.getActive();
//var ss = SpreadsheetApp.openById(e.parameter.ID);
var sh = ss.getSheets()[0];
//var sh = ss.getSheetByName(e.parameter.SH);
sh.deleteRow(parseInt(record) + 1); //makes the correct row to delete (because of header row)
return ContentService.createTextOutput("Success, requested action completed");
}
}
postman says problem line in script code line 15. ( var sh = ss.getSheets()[0]; // Postman problem line)
Also I am using turkish language on google sheets. english name Sheet1 turkish language Sayfa1
I tried both names.
but unsuccess.
I am using this line for the connection spreadsheet.
https://script.google.com/macros/s/AKfycbyTt9oaz10WuKh0822hBncRoJZAw-D4hcGMwJwdy95l8H_mXfE/exec?ID=18NFZD7vZ-JySbbV7jiZMBpiBsoLJ4IQge9Wk9cL6Z4c&SH=Sheet1&func=ReadAll
Please help.
Thanks
Problem solved. The problem is the sharing problem. When sharing, it should be (Anyone, even anonymous). google always wanted me to sign in. When sharing (script code file) must be, In the 1st window, (me and gmail address) should be selected. (Anyone, even anonymous) should be selected in the 2nd window. sheet name not problem

iOS UIWebView totally fails to understand more than one #font-face?

Notice this simple css/html which is being displayed in a local UIWebView:
there's the simulator showing it...
Notice there are two #font-face definitions.
But ... only the second one works. If you swap them around, only the second one works.
So here ...
#font-face {
font-family:'aaa';
src: local('SourceSansPro-Regular'),
url('SourceSansPro-Regular.ttf') format('truetype');
}
#font-face {
font-family:'bbb';
src: local('SourceSansPro-BoldIt'),
url('SourceSansPro-BoldItalic.ttf') format('truetype');
}
only "bbb" works, the other one seems to be "cancelled". Then here ..
#font-face {
font-family:'bbb';
src: local('SourceSansPro-BoldIt'),
url('SourceSansPro-BoldItalic.ttf') format('truetype');
}
#font-face {
font-family:'aaa';
src: local('SourceSansPro-Regular'),
url('SourceSansPro-Regular.ttf') format('truetype');
}
only "aaa" works, the other one seems to be "cancelled".
Here's how to do it in Swift,
// load a simple UIWebView (say, an "about" or "legal" screen)
// base is in template.html
import UIKit
import WebKit
class MinorWebView:UIViewController
{
#IBOutlet var wv:UIWebView!
#IBInspectable var filename:String = "?"
// for example, "about" for "about.html"
...
func makeHtml()
{
print("making html for ... " ,filename)
let ourSize = grid.yourSizeDecisionMechanism
let sizeString = String(format:"%.0f", ourSize)
let p1 = NSBundle.mainBundle().pathForResource("template", ofType: "html")
var html:String = try! NSString(contentsOfFile:p1!, encoding:NSUTF8StringEncoding) as String
let p2 = NSBundle.mainBundle().pathForResource(filename, ofType: "html")
let content:String = try! NSString(contentsOfFile:p2!, encoding:NSUTF8StringEncoding) as String
html = html.stringByReplacingOccurrencesOfString("STUFF", withString:content)
html = html.stringByReplacingOccurrencesOfString("SIZEPOINTS", withString:sizeString)
print("Made html like this ---\n" ,html ,"\n------")
wv.loadHTMLString(html as String, baseURL:nil)
}
}
Simply drag "template.html" and "about.html" in to the project (just as you would with an image); ensure they have target membership.
You have an error in the <style> block: it starts with a <meta> element. This will throw the parser off; apparently it thinks that everything up until the first } is bad and needs to be discarded.
Solution: take the <meta> out of the <style>.

Mozilla: openTab fails in recent version

In a Firefox extension, I open new tabs:
var tab = gBrowser.addTab(url, referrer, null, postData, null, null);
With Firefox 30, this fails, sometimes, after 9 tabs opened:
TypeError: this.selectedItem is null
However, the number of tabs does increase by 1 (checked with gBrowser.browsers.length).
I tried this alternative code, but I get the same error after a while:
var wm = Components.classes["#mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
var my_browser = wm.getMostRecentWindow("navigator:browser").getBrowser();
var tab = my_browser.addTab(url, referrer, null, postData, null, null);
Somehow this was fixed by changing some of the custom CSS used to modify the display of the browser
#navigator-toolbox {
/*display: none;*/ /* causes crashes!!! */
max-height: 0;
overflow: hidden;
}
#TabsToolbar {
/*display: none;*/ /* causes crashes!!! */
max-height: 0;
overflow: hidden;
}

MVC Bundling breaking my calc CSS statements by removing spaces?

I have css statements like this:
margin-left: calc(50% - 480px);
Which work fine unminified but as soon as I begin minifying, the statement gets changed to:
margin-left: calc(50%- 480px);
Rendering all calc statements broken. Similar things happen with width, max-width, min-width, etc. Is there any way I can change the behavior of the bundle to leave those CSS properties alone?
Currently I'm just using bundles.Add(new Bundle()) to prevent minification entirely, but it would be nice if I could minify correctly.
This is an issue of the optimizer.
To avoid the miniffier to remove the whitespaces, group the affected element with parenthesis. That workarrounds the issue.
margin-left: calc((50%) - 480px);
In addition to the answer above:
if you use:
margin-left: calc((50%) + 480px);
You should rewrite it as:
margin-left: calc((50%) - -480px);
Since it didn't seem to fix (50%)+ for me.
If the default css minification is not doing what you need, you can always use a third party one.
bundling allows you to use your own transformations using IBundleTransform
var bundle = new Bundle("~/Content/css", myCustomCssTransform);
there are many different bundlers - nuget
for example you could use YUI compressor:
using System.IO;
using System.Web.Optimization;
using Yahoo.Yui.Compressor;
namespace Bundler.Utilities
{
public enum contentType
{
javascript,
css
}
public class YUITransform : IBundleTransform
{
readonly string _contentType = string.Empty;
public YUITransform(contentType contentType)
{
if (contentType == contentType.css)
{
this._contentType = "text/css";
}
else
{
this._contentType = "text/javascript";
}
}
public void Process(BundleContext context, BundleResponse bundle)
{
bundle.ContentType = this._contentType;
string content = string.Empty;
foreach (FileInfo file in bundle.Files)
{
using (StreamReader fileReader = new
StreamReader(file.FullName)) {
content += fileReader.ReadToEnd();
fileReader.Close();
}
}
bundle.Content = Compress(content);
}
string Compress(string content) {
if (_contentType == "text/javascript")
{
return JavaScriptCompressor.Compress(content);
}
else
{
return CssCompressor.Compress(content,
CssCompressionType.StockYuiCompressor
);
}
}
}
}
This is totally normal as referring to CSS Values and Units Module it states
The following features are at-risk and may be dropped during the CR
period: ‘calc()’, ‘toggle()’, ‘attr()’."
If you could skip the spaces there, that wouldn't be a complete minifying. An option is replacing spaces with unicode caracter \00A0
No idea why but calc((50%) - 480px) didnt work for me, however the following worked:
subtraction:
margin-left: calc(((100%) - (480px)))
addition:
margin-left: calc((100%) - -480px)
Beware of using variables in calc. You can end up with another CssMinify() bug:
#myVariable: 0em;
margin-left: calc((50%) - #myVariable);
is compressed and unit is cut off:
margin-left: calc((50%) - 0);
and it is not valid calc() call too!
It seems the issue has been fixed in the version 2.4.9 of YUI Compressor, which can be accessed from here https://mvnrepository.com/artifact/com.yahoo.platform.yui/yuicompressor?repo=bsi-business-systems-integration-ag-scout. I have used this css file:
body{
font-size: calc(50% - 3px);
font-size: calc(50% + 3px);
font-size: calc(50% + +3px);
font-size: calc((50%) + (3px));
font-size: calc(50% + (+3px));
font-size: calc(50% + (3px));
font-size: calc(50% - (-3px));
font-size: calc(50% - -3px);
}
and running this command:
java -jar yuicompressor-2.4.9-BSI-2.jar --line-break 0 -o process.css.min.gz file.css
generates this output, which looks good:
body{font-size:calc(50% - 3px);font-size:calc(50% + 3px);font-size:calc(50% + +3px);font-size:calc((50%)+(3px));font-size:calc(50% + (+3px));font-size:calc(50% + (3px));font-size:calc(50% - (-3px));font-size:calc(50% - -3px)}

Resources