How to use the ghost/utils/bound-one-way function in ghost

To help you get started, we’ve selected a few ghost examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TryGhost / Ghost-Admin / app / controllers / post-settings-menu.js View on Github external
promise = RSVP.resolve(afterSave).then(() => {
            return this.get('slugGenerator').generateSlug('post', title).then((slug) => {
                if (!isBlank(slug)) {
                    this.set(destination, slug);
                }
            }).catch(() => {
                // Nothing to do (would be nice to log this somewhere though),
                // but a rejected promise needs to be handled here so that a resolved
                // promise is returned.
            });
        });

        this.set('lastPromise', promise);
    },

    metaTitleScratch: boundOneWay('model.metaTitle'),
    metaDescriptionScratch: boundOneWay('model.metaDescription'),

    seoTitle: computed('model.titleScratch', 'metaTitleScratch', function () {
        let metaTitle = this.get('metaTitleScratch') || '';

        metaTitle = metaTitle.length > 0 ? metaTitle : this.get('model.titleScratch');

        if (metaTitle.length > 70) {
            metaTitle = metaTitle.substring(0, 70).trim();
            metaTitle = Handlebars.Utils.escapeExpression(metaTitle);
            metaTitle = Ember.String.htmlSafe(`${metaTitle}…`);
        }

        return metaTitle;
    }),
github TryGhost / Ghost-Admin / app / controllers / post-settings-menu.js View on Github external
return this.get('slugGenerator').generateSlug('post', title).then((slug) => {
                if (!isBlank(slug)) {
                    this.set(destination, slug);
                }
            }).catch(() => {
                // Nothing to do (would be nice to log this somewhere though),
                // but a rejected promise needs to be handled here so that a resolved
                // promise is returned.
            });
        });

        this.set('lastPromise', promise);
    },

    metaTitleScratch: boundOneWay('model.metaTitle'),
    metaDescriptionScratch: boundOneWay('model.metaDescription'),

    seoTitle: computed('model.titleScratch', 'metaTitleScratch', function () {
        let metaTitle = this.get('metaTitleScratch') || '';

        metaTitle = metaTitle.length > 0 ? metaTitle : this.get('model.titleScratch');

        if (metaTitle.length > 70) {
            metaTitle = metaTitle.substring(0, 70).trim();
            metaTitle = Handlebars.Utils.escapeExpression(metaTitle);
            metaTitle = Ember.String.htmlSafe(`${metaTitle}…`);
        }

        return metaTitle;
    }),

    seoDescription: computed('model.scratch', 'metaDescriptionScratch', function () {
github TryGhost / Ghost-Admin / app / controllers / post-settings-menu.js View on Github external
let deferred = {};

        deferred.promise = this.store.query('user', {limit: 'all'}).then((users) => {
            return users.rejectBy('id', 'me').sortBy('name');
        }).then((users) => {
            return users.filter((user) => {
                return user.get('active');
            });
        });

        return ArrayProxy
            .extend(PromiseProxyMixin)
            .create(deferred);
    }),

    slugValue: boundOneWay('model.slug'),

    // Requests slug from title
    generateAndSetSlug(destination) {
        let title = this.get('model.titleScratch');
        let afterSave = this.get('lastPromise');
        let promise;

        // Only set an "untitled" slug once per post
        if (title === '(Untitled)' && this.get('model.slug')) {
            return;
        }

        promise = RSVP.resolve(afterSave).then(() => {
            return this.get('slugGenerator').generateSlug('post', title).then((slug) => {
                if (!isBlank(slug)) {
                    this.set(destination, slug);