Atom Editor Not Reading All The Snippets in Snippets.cson - coffeescript

My snippets.cson:-
'*':
'WordPress theme directory':
'prefix': 'wpThemeDirectoryUri'
'body': """
get_template_directory_uri()
"""
'*':
'WordPress Site URL (No Trailing Slash)':
'prefix': 'wpSiteUrl'
'body': """
site_url()
"""
In the editor, when I press alt + shift + s hotkey to search for available snippets and type "wp", it lists only wpSiteUrl.
Should not it also list wpThemeDirectoryUri?
If I remove second snippet. It lists wpThemeDirectoryUri.
I've big snippets and your solution must support multiline snippets.

After reading #lee-dohm answer at:-
Atom Editor: multiple snippets
I found the solution:-
'*':
'WordPress theme directory':
'prefix': 'wpThemeDirectoryUri'
'body': """
get_template_directory_uri()
"""
'WordPress Site URL (No Trailing Slash)':
'prefix': 'wpSiteUrl'
'body': """
site_url()
"""

Related

How to get file name when overriding VS Code snippet

I'm trying to override the rfce snippet in VS code but I can't seem to be able to get the filename autofilled when there's a named file. Where the file is not saved(unnamed) it should just be NameOfComponent but if the file is saved(has a name), the snippet should name the component the same as the file name but without the extension. Here's what I have so far:
"React Component": {
"prefix": "rfce",
"body": [
"import React, { useState, useEffect } from \"react\";",
"",
"const ${1:NameOfComponent} = () => {",
" return (",
" <>",
" ${2:<div>Hello World</div>}",
" </>",
" );",
"};",
"",
"export default ${1:NameOfComponent};"
],
"description": "React Component"
}
If you want to make your snippet into a template for new files see https://stackoverflow.com/a/73043147/836330. Snippet template functionality is being built in to vscode.
Presumably you have found $TM_FILENAME_BASE from vscode snippet variables documentation as the variable you need to get the file name of the current file without its extension.
Ideally what you would like to do is a choice element (see Choice doc and something like this:
"const ${1|NameOfComponent},$TM_FILENAME_BASE|}...", // does not work
That won't work because according to the snippet grammar choice options can only be text:
choice ::= '${' int '|' text (',' text)* '|}'
So you would have to simulate a choice as close as possible. The following snippet does that in two ways:
"React Component": {
"prefix": "rfce",
"body": [
"import React, { useState, useEffect } from \"react\";",
"",
// "const ${1:NameOfComponent}${2:$TM_FILENAME_BASE} = () => {", // option 1 works
"const ${1:${2:NameOfComponent}${3:$TM_FILENAME_BASE}} = () => {", // option 2 works
" return (",
" <>",
" ${4:<div>Hello World</div>}",
" </>",
" );",
"};",
"",
"export default $1;" // uses option 2
],
"description": "React Component"
}
Option 1 simply lists both ${1:NameOfComponent}${2:$TM_FILENAME_BASE} presents both "options" - each will be selected in turn, just delete the one you don't want when it is selected and tab to go on. This is pretty straightforward but does require you to use the whole construction ${1:NameOfComponent}${2:$TM_FILENAME_BASE} every time you want that value.
Option 2 wraps the whole thing in another tabstop:
${1:${2:NameOfComponent}${3:$TM_FILENAME_BASE}}} which is a little trickier but then the result is put into tabstop $1 and then that is all you need to refer to when you want the result (as in the last line of the snippet).
You just have to practice a little - there is an extra tab at the start to select NameOfComponent. To accept it just tab past it to select the fileName and delete that, or vice versa - delete NameOfComponent when it is selected and tab to select the fileName - if you want it just tab to go on to the next tabstop.
The result of that inital tabstop will be put into $1 which can then be used elsewhere without the need to go through the option selection stuff again.
Here is a demo using option 2:
You can use TM_FILENAME_BASE - The filename of the current document without its extensions
Example for a react functional typed component:
"create react functional component": {
"prefix": "trafce",
"body": [
"import { FC } from \"react\"",
"\n",
"interface Props {\n\n}",
"\n",
"const $TM_FILENAME_BASE:FC<Props> = ({}) => {",
" return (",
" <div> ${1:$TM_FILENAME_BASE} </div>",
" )",
"}",
"\n",
"export default $TM_FILENAME_BASE"
],
"description": "Create a react-typed functional component "
}
See the demo
Demo for the code snippet

Amazon SES send_email Text body with spacing/newlines

I am facing an issue where all of my text e-mails are scrunched together and do not have new lines persisting through the sending process.
Here is the code:
def send_ses_message(email_to, subject, body):
ses = init_ses_internal()
if ses:
ses.send_email(
Source='no-reply#domain.com',
Destination={
'ToAddresses': [
email_to,
],
},
Message={
'Subject': {
'Data': subject,
},
'Body': {
'Text': {
'Data': body,
'Charset': 'UTF-8',
},
'Html': {
'Data': body,
'Charset': 'UTF-8',
},
}
},
ReplyToAddresses=[
'mharris#domain.com', # just in case someone replies to a no-reply# address I'll receive them
],
ReturnPath='mharris#domain.com', # bounce backs will come to me also
)
return True
I have most recently tried forcing UTF-8 hoping that would allow the newlines to persist. After that I added \n where a new line should exist.
Here is an example of a email:
def send_reset_email(self, email_to, unique_id):
subject = "Company Password Reset"
body = """
Hello!\n\n
We have received a request to reset your password.\n
Please click the link below to proceed with resetting your password. Note: this link will expire in 1 hour.\n\n
http://staging.domain.com/password/reset/{}\n\n
If you did not request this reset you can safely ignore this e-mail.\n\n
Thank you for choosing Company!\n\n
The Company Team\n
www.company.com\n
""".format(unique_id)
send_ses_message(email_to, subject, body)
Please let me know what I can do to ensure that newlines are persistent across Amazon SES. Thanks!
The default content type in SES seems to be text/html, so using <br> instead of \n worked for me
Edit: I was having a similar issue with outlook 2013 clients. Adding a tab character before the newline worked for me.
Replacing \n with \t\n
Or \t\r\n
How do I format a String in an email so Outlook will print the line breaks?
I faced similar issue in sending a contents of log file (stored in variable) to HTML BODY.
Replacing the new line with "<br />" as below helped solve the problem. Below command replaces all newline characters in the text with "<br />".
mytext = mytext.split("\n").join("<br />")

Multiple files upload using swagger operation

I am currently doing multiple files upload using swagger operation. Following are the codes that I am working with:
class uploadImage(Resource):
#swagger.operation(
notes='Upload an image file',
parameters=[
{
"name": "file[]",
"description": "Upload an image file. File size limit is 3MB. Only '.jpg' is allowed ",
"required": True,
"allowMultiple": True,
"dataType": 'file',
"paramType": "form"
}
])
def post(self):
files=request.files.getlist['file[]']
filenames = []
for file in files:
filename = secure_filename(file.filename)
filenames.append(filename)
print "Files are uploaded successfully"
Although I inserted "allowMultiple":True in the code, but it did not show in the swagger UI. Once the server is up, I try to view the html source code, "multiple" does not display in the form.
Following is the source code for swagger ui when the server is up:
<input class="parameter" type="file" name="file[]">
The word "multiple" is missing from the .
If I edit the source code and add in the word "multiple" as below, I manage to select multiple files.
<input class="parameter" type="file" name="file[]" multiple>
It seems like "allowMultiple":True does not work for me in this case.
Any idea or suggestion for me?
Thank you.
That's just not supported by Swagger. See https://github.com/swagger-api/swagger-spec/issues/254.
this already support by swagger in OpenAPI 3.0. See https://swagger.io/docs/specification/describing-request-body/file-upload/
example:
/schema:
get:
tags:
- Schema
description: download schema file
responses:
"200":
description: success
content:
multipart/form-data:
schema:
type: object
properties:
filename:
type: array
items:
type: string
format: binary
"400":
$ref: "#/components/responses/failed"
"404":
$ref: "#/components/responses/notExist"
effect picture

Integration Roxy Fileman in TinyMCE

I'm trying to integrate the Roxy Fileman (http://www.roxyfileman.com) in TinyMCE.
Unable to make the icon appear Roxy Fileman after clicking Trigger Image of TinyMCE but it is not working correctly.
When I open the Roxy Fileman received from these mistakes obvious warning from Chrome:
E_LoadingConf
E_ActionDisabled
Error loading language file
I have already sent a message to the staff of the Roxy Fileman but got no answer.
Can anyone help me integrate this? I need a way to upload photos on TinyMCE.
If anyone has any other plugin to indicate I accept.
Below is my code:
<script type="text/javascript" src="js/tinymce/tinymce.min.js"></script>
<script>
// This must be set to the absolute path from the site root.
var roxyFileman = 'js/tinymce/plugins/fileman/index.html?integration=tinymce4';
$(function() {
tinyMCE.init({language : 'pt_BR', selector: 'textarea#elm1', menubar : false, plugins: 'advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking save table contextmenu directionality template paste textcolor',
toolbar: "insertfile undo redo | bold italic underline | alignleft aligncenter alignright alignjustify | link image | bullist numlist outdent indent | forecolor", file_browser_callback: RoxyFileBrowser});
});
function RoxyFileBrowser(field_name, url, type, win) {
var cmsURL = roxyFileman; // script URL - use an absolute path!
if (cmsURL.indexOf("?") < 0) {
cmsURL = cmsURL + "?type=" + type;
}
else {
cmsURL = cmsURL + "&type=" + type;
}
cmsURL += '&input=' + field_name + '&value=' + document.getElementById(field_name).value;
tinyMCE.activeEditor.windowManager.open({
file: cmsURL,
title: 'Upload de Arquivos',
width: 850, // Your dimensions may differ - toy around with them!
height: 650,
resizable: "yes",
plugins: "media",
inline: "yes", // This parameter only has an effect if you use the inlinepopups plugin!
close_previous: "no"
}, {
window: win,
input: field_name
});
return false;
}
</script>
*TinyMCE is 4.0.16 (2014-01-31). Roxy'm running on Windows server with support for PHP 5.2.17.
Thank you for your attention.
Have you tried changing the conf.json file
the integration should be changed from custom to :-
"INTEGRATION": "tinymce4",
And possibly in your web config adding
<system.webServer>
...
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
...
It seems that Roxy Fileman configuration and language files are misssing or contain syntax errors.
Try to load js/tinymce/plugins/fileman/conf.json in your browser and see the result. All configuration and language files are in json format and must be utf8 encoded.
You can also debug using developer tools -> network to see the server responses when Fileman initializes.
E_LoadingConf means that configuration file cannot be loaded or parsed.
E_ActionDisabled is because the configuration is not loaded
E_LoadingConf and E_ActionDisabled Error loading language file are errors that might be caused because your server is not configured to handle json files properly.
You will need to configure json as a new mime type.
If your server works with IIS, you need to follow the steps listed on this page
Good luck !
Try changes this
document.getElementById(field_name)
To be
document.getElementById("your_id_tinymce")

coffeescript unexpected INDENT

Sometimes when I edit coffeescript files in Sublime text2 I got errors when compile it to js:
error: unexpected INDENT
$.post url,
In sublime text2 editor I see valid indents:
But if I copy paste this code in plain editor I see wrong indents:
click: ->
debugger;
# delete org here
$.post url,
debugger; string has wrong extra indent.
So how to edit coffeescript files in sublime text 2 with pleasure?
I got installed coffeescript package in sublime.
My Preferences.sublime-settings file is the following:
{
"auto_indent": true,
"auto_match_enabled": true,
"detect_indentation": true,
"draw_centered": false,
"font_size": 11.0,
"ignored_packages":
[
"Better CoffeeScript",
"Vintage"
],
"indent_guide_options":
[
"draw_active"
],
"indent_subsequent_lines": true,
"indent_to_bracket": true,
"smart_indent": true,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_automatic_white_space": true,
"use_tab_stops": true,
"word_wrap": "auto",
"wrap_width": 0
}
It looks like you are mixing tabs and spaces. Select View->Indentation and make sure that Indent Using Spaces is checked, then click Convert Indentation to Spaces and you should be all set.