From 319230e703d6ff0b8a515c07923ba5706d79f971 Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Fri, 8 Apr 2016 17:30:39 -0400 Subject: [PATCH] 1.0.0 Version This version adds advanced mode, and some little refactors --- README.md | 7 ++-- .../initializers/extend-for-signatures.js.es6 | 33 +++++++++++-------- .../post-after-cooked/signature.hbs | 6 ---- .../signature-preferences.hbs | 32 ++++++++++++------ config/locales/server.en.yml | 1 + config/settings.yml | 3 ++ plugin.rb | 13 +++++--- 7 files changed, 60 insertions(+), 35 deletions(-) delete mode 100644 assets/javascripts/discourse/templates/connectors/post-after-cooked/signature.hbs diff --git a/README.md b/README.md index c54dffe..e3d8b88 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,10 @@ And each user need to enable and select a signature on his/her profile: and thats it! +## Advanced Mode + +You can now enable **advanced mode** on the plugin settings and use a full blow post editor to create your signature! With text, multiple images, etc. + ## About This is a work in progress! Feel free to use and ask questions here, or on [Meta](meta.discourse.org). @@ -34,5 +38,4 @@ This is a work in progress! Feel free to use and ask questions here, or on [Meta ## TODO - Figure out a way so the user doens't have to refresh te browser to change the `see signatures` options. -- Use d-editor instead of a simple text field. (Allow text sigs, multi-images, etc) -- Get some sane defaults for CSS +- Cache the cooked signatures diff --git a/assets/javascripts/discourse/initializers/extend-for-signatures.js.es6 b/assets/javascripts/discourse/initializers/extend-for-signatures.js.es6 index 22297fd..fe85b62 100644 --- a/assets/javascripts/discourse/initializers/extend-for-signatures.js.es6 +++ b/assets/javascripts/discourse/initializers/extend-for-signatures.js.es6 @@ -1,27 +1,25 @@ -import Post from 'discourse/models/post'; +import Preferences from 'discourse/controllers/preferences'; import { withPluginApi } from 'discourse/lib/plugin-api'; - -function oldPluginCode() { - Post.reopen({ - showSignatures: function() { - return Discourse.User.currentProp("custom_fields.see_signatures"); - }.property() - }); -} +import RawHtml from 'discourse/widgets/raw-html'; function attachSignature(api) { - api.includePostAttributes('user_signature_url'); + api.includePostAttributes('user_signature'); api.decorateWidget('post-contents:after', dec => { const attrs = dec.attrs; - if (Ember.isEmpty(attrs.user_signature_url)) { return; } + if (Ember.isEmpty(attrs.user_signature)) { return; } const currentUser = api.getCurrentUser(); + const siteSettings = Discourse.SiteSettings; // TODO: change way to get the sitesettings if (currentUser) { const enabled = currentUser.get('custom_fields.see_signatures'); if (enabled) { - return [dec.h('hr'), dec.h('img.signature-img', { attributes: { src: attrs.user_signature_url } } )]; + if (siteSettings.signatures_advanced_mode) { + return [dec.h('hr'), dec.h('div', new RawHtml({html: `
${Discourse.Markdown.cook(attrs.user_signature)}
`}))]; + } else { + return [dec.h('hr'), dec.h('img.signature-img', {attributes: {src: attrs.user_signature}})]; + } } } }); @@ -32,7 +30,16 @@ export default { initialize(container) { const siteSettings = container.lookup('site-settings:main'); if (siteSettings.signatures_enabled) { - withPluginApi('0.1', attachSignature, { noApi: oldPluginCode }); + withPluginApi('0.1', attachSignature); + + Preferences.reopen({ + signaturesEnabled: function() { + return Discourse.SiteSettings.signatures_enabled; + }.property(), + signaturesAdvancedMode: function() { + return Discourse.SiteSettings.signatures_advanced_mode; + }.property() + }); } } }; diff --git a/assets/javascripts/discourse/templates/connectors/post-after-cooked/signature.hbs b/assets/javascripts/discourse/templates/connectors/post-after-cooked/signature.hbs deleted file mode 100644 index 9d999bc..0000000 --- a/assets/javascripts/discourse/templates/connectors/post-after-cooked/signature.hbs +++ /dev/null @@ -1,6 +0,0 @@ -{{#if showSignatures}} - {{#if user_signature_url}} -
- - {{/if}} -{{/if}} diff --git a/assets/javascripts/discourse/templates/connectors/user-custom-preferences/signature-preferences.hbs b/assets/javascripts/discourse/templates/connectors/user-custom-preferences/signature-preferences.hbs index e425951..f3c70a9 100644 --- a/assets/javascripts/discourse/templates/connectors/user-custom-preferences/signature-preferences.hbs +++ b/assets/javascripts/discourse/templates/connectors/user-custom-preferences/signature-preferences.hbs @@ -1,10 +1,22 @@ -
- - -
+{{#if signaturesEnabled}} +
+ +
+ +
+
+ + {{#if signaturesAdvancedMode}} + {{d-editor value=controller.model.custom_fields.signature_raw showUploadModal="showUploadModal"}} + {{else}} + + {{/if}} +
+
Signature Code
+
+{{/if}} diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 43db2bb..af867a9 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1,3 +1,4 @@ en: site_settings: signatures_enabled: "Enable user-made signatures below posts?" + signatures_advanced_mode: "Let users use a full blow post editor to create signatures. RESETS all existing signatures. Needs a server restart" diff --git a/config/settings.yml b/config/settings.yml index cc6e0d2..2a4583c 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -2,3 +2,6 @@ plugins: signatures_enabled: default: true client: true + signatures_advanced_mode: + default: false + client: true diff --git a/plugin.rb b/plugin.rb index 5be56a8..ed3bbb0 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,6 +1,6 @@ # name: discourse-signatures # about: A plugin to get that nostalgia signatures in Discourse Foruns -# version: 0.1.0 +# version: 1.0.0 # author: Rafael Silva # url: https://github.com/xfalcox/discourse-signatures @@ -8,15 +8,21 @@ enabled_site_setting :signatures_enabled DiscoursePluginRegistry.serialized_current_user_fields << "see_signatures" DiscoursePluginRegistry.serialized_current_user_fields << "signature_url" +DiscoursePluginRegistry.serialized_current_user_fields << "signature_raw" after_initialize do User.register_custom_field_type('see_signatures', :boolean) User.register_custom_field_type('signature_url', :text) + User.register_custom_field_type('signature_raw', :text) if SiteSetting.signatures_enabled then - add_to_serializer(:post, :user_signature_url, false) { - object.user.custom_fields['signature_url'] + add_to_serializer(:post, :user_signature, false) { + if SiteSetting.signatures_advanced_mode then + object.user.custom_fields['signature_raw'] + else + object.user.custom_fields['signature_url'] + end } # I guess this should be the default @ discourse. PR maybe? @@ -31,5 +37,4 @@ after_initialize do end register_asset "javascripts/discourse/templates/connectors/user-custom-preferences/signature-preferences.hbs" -register_asset "javascripts/discourse/templates/connectors/post-after-cooked/signature.hbs" register_asset "stylesheets/common/signatures.scss"