New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

apostrophe-snippets

Package Overview
Dependencies
Maintainers
8
Versions
202
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apostrophe-snippets - npm Package Compare versions

Comparing version 0.0.29 to 0.0.30

31

index.js

@@ -95,2 +95,3 @@ var async = require('async');

self._perPage = options.perPage || 10;
self._browserOptions = options || {};

@@ -467,6 +468,6 @@ // self.modules allows us to find the directory path and web asset path to

function(callback) {
self.afterUpdate(req, originalSlug, snippet, callback);
self.afterUpdate(req, req.body, snippet, callback);
},
function(callback) {
self.afterSave(req, originalSlug, snippet, callback);
self.afterSave(req, req.body, snippet, callback);
}

@@ -1325,13 +1326,19 @@ ], callback);

var browserOptions = options.browser || {};
// The option can't be .constructor because that has a special meaning
// in a javascript object (not the one you'd expect, either) http://stackoverflow.com/questions/4012998/what-it-the-significance-of-the-javascript-constructor-property
var browser = {
pages: browserOptions.pages || 'aposPages',
construct: browserOptions.construct || getBrowserConstructor()
var browser = options.browser || {};
var pages = browser.pages || 'aposPages';
var construct = browser.construct || getBrowserConstructor();
self._pages.addType(self);
var args = {
name: self.name,
instance: self._instance,
icon: self._icon,
css: self._css,
typeCss: self._typeCss,
manager: self.manager,
action: self._action
};
self._pages.addType(self);
self._apos.pushGlobalCallWhen('user', '@.replaceType(?, new @(?))', browser.pages, self.name, browser.construct, { name: self.name, instance: self._instance, icon: self._icon, css: self._css, typeCss: self._typeCss, manager: self.manager, action: self._action });
extend(true, args, browser.options || {});
self._apos.pushGlobalCallWhen('user', '@.replaceType(?, new @(?))', pages, self.name, construct, args);
if (options.widget) {

@@ -1347,3 +1354,3 @@ var widgetConstructor;

new widgetConstructor({ apos: self._apos, icon: self.icon, app: self._app, snippets: self, name: self.name, label: self.label });
self._apos.pushGlobalCallWhen('user', '@.addWidgetType()', browser.construct);
self._apos.pushGlobalCallWhen('user', '@.addWidgetType()', construct);
}

@@ -1350,0 +1357,0 @@

{
"name": "apostrophe-snippets",
"version": "0.0.29",
"version": "0.0.30",
"description": "Reusable content snippets for the Apostrophe content management system. The blog and events modules are built on this foundation, which is also useful in and of itself.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -189,6 +189,11 @@ // NOTES FOR REUSE:

if (action === 'update') {
self.beforeUpdate($el, data, go);
self.beforeUpdate($el, data, afterAction);
} else {
self.beforeInsert($el, data, go);
self.beforeInsert($el, data, afterAction);
}
// beforeSave is more convenient in most cases
function afterAction() {
apos.log('calling beforeSave');
self.beforeSave($el, data, go);
}

@@ -195,0 +200,0 @@ function go() {

@@ -36,3 +36,3 @@ # apostrophe-snippets

The bare requirements for each of these template overrides is an index.js file (/my-project/lib/snippets/index.js) and a client-side file called "main.js" which lives in a directory named "public/js" (/my-project/lib/snippets/public/js/main.js). We'll take a brief look at the bare bones of these files below.
The bare requirements for each of these template overrides is an index.js file (/my-project/lib/snippets/index.js) and a client-side file called "editor.js" which lives in a directory named "public/js" (/my-project/lib/snippets/public/js/editor.js). We'll take a brief look at the bare bones of these files below.

@@ -78,3 +78,3 @@ But first, we'll need to update our app.js. Using our snippets example from above, we'll change our initAposSnippets function in app.js to the following:

In addition to the server-side file, we'll need to build a file for the browser to access and build from. So we'll create a file named "main.js" in a "js" directory inside of a "public" directory in this module override (i.e. /my-project/lib/snippets/public/js/main.js). We'll throw the following base functionality into that main.js file:
In addition to the server-side file, we'll need to build a file for the browser to access and build from. So we'll create a file named "editor.js" in a "js" directory inside of a "public" directory in this module override (i.e. /my-project/lib/snippets/public/js/editor.js). We'll throw the following base functionality into that editor.js file:

@@ -92,3 +92,3 @@ // No changes to the browser-side behavior of snippets for now

In this main.js file, we're simply connecting the override module to the original module's functionality. We're not getting fancy here (you can read about extending the functionality below).
In this editor.js file, we're simply connecting the override module to the original module's functionality. We're not getting fancy here (you can read about extending the functionality below).

@@ -368,3 +368,3 @@ Once again, we'll need to update the aposInitSnippets function in our app.js to make sure we're calling the right constructor on the browser-side:

Next we'll need to send our extra properties to the server when a snippet is saved. Until this point all of the code we've looked at has been on the server side. But of course snippets also have browser-side JavaScript code to implement the "new," "edit" and "manage" dialogs. You can find that code in `apostrophe-snippets/public/js/main.js`.
Next we'll need to send our extra properties to the server when a snippet is saved. Until this point all of the code we've looked at has been on the server side. But of course snippets also have browser-side JavaScript code to implement the "new," "edit" and "manage" dialogs. You can find that code in `apostrophe-snippets/public/js/editor.js`.

@@ -377,6 +377,8 @@ Just like the server side code, this browser side code can be subclassed and extended. In fact, we must extend it for our new subclass of snippets to work. Here's how to do that:

3. Create a `main.js` file in that folder.
3. Create an `editor.js` file and a `content.js` file in that folder.
Here's what `main.js` looks like for the blog module:
`editor.js` will house all of the logic for subclassing snippets and is only loaded in the browser if a user is logged in. `content.js` is always loaded, giving us a convenient way to split up the logic between the _editing_ interface of the blog and the javascript related to showing it. We won't be making use of `content.js` for our Blog, but if we were making a widget such as a slideshow that required some logic this is where we would put it.
Here's what `editor.js` looks like for the blog module:
function AposBlog(optionsArg) {

@@ -415,3 +417,3 @@ ...

But we still haven't seen how extra properties of a snippet are handled. So let's look at that code from `main.js` in the blog module.
But we still haven't seen how extra properties of a snippet are handled. So let's look at that code from `editor.js` in the blog module.

@@ -480,8 +482,10 @@ We'll create a `findExtraFields` function to take care of locating the fields in the form via jQuery and storing them in a `data` object provided by the caller. Note this function takes a callback so you can do time-consuming tasks if necessary:

Great, but how does our `main.js` file make it to the browser? And what about the various templates that are instantiated on the browser side to display modals like "New Blog Post" and "Manage Blog Posts?"
Great, but how do our `editor.js` and `content.js` files make it to the browser? And what about the various templates that are instantiated on the browser side to display modals like "New Blog Post" and "Manage Blog Posts?"
The answer is that the snippet module pushes them there for us:
self.pushAsset('script', 'main');
self.pushAsset('stylesheet', 'main');
self.pushAsset('script', 'editor');
self.pushAsset('stylesheet', 'editor');
self.pushAsset('script', 'content');
self.pushAsset('stylesheet', 'content');
self.pushAsset('template', 'new');

@@ -494,3 +498,3 @@ self.pushAsset('template', 'edit');

So you don't need to worry about delivering any of the above files (`main.js`, `main.less`, `new.html`, `edit.html`, `manage.html`, and `import.html`). But if you wish to push additional browser-side assets as part of every page request, now you know how.
So you don't need to worry about delivering any of the above files (`editor.js`, `editor.less`, `content.js`, `content.less`, `new.html`, `edit.html`, `manage.html`, and `import.html`). But if you wish to push additional browser-side assets as part of every page request, now you know how.

@@ -661,3 +665,3 @@ ### Saving Extra Properties on the Server

We also need a bare-bones `lib/modules/pressReleases/public/js/main.js` file on the browser side:
We also need a bare-bones `lib/modules/pressReleases/public/js/editor.js` file on the browser side:

@@ -664,0 +668,0 @@ function PressReleases(options) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc