From 1ff4e7e1d57eed825febdbd58980a73bef03cb6b Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Sun, 6 Dec 2015 15:56:46 -0200 Subject: [PATCH] New and improved working version --- README.md | 24 +++-------------- .../post-after-cooked/signature.hbs | 10 +++---- assets/stylesheets/common/signatures.scss | 0 config/locales/server.en.yml | 2 -- config/settings.yml | 6 ----- plugin.rb | 26 ++++++++++++++++--- 6 files changed, 29 insertions(+), 39 deletions(-) create mode 100644 assets/stylesheets/common/signatures.scss diff --git a/README.md b/README.md index 53bc4ca..970ff3c 100644 --- a/README.md +++ b/README.md @@ -2,32 +2,14 @@ Felling nostalgic of old VBulletin days? Wanna spam and flame like it's 2000? +![signature](https://cloud.githubusercontent.com/assets/1385470/11614719/c94ba4aa-9c31-11e5-9f32-67decaf0f3d3.png) + **Install Discourse Signatures!** -## Before Installation - -Since this is an early MVP the installation process is a bit, complicated. - -First you need to create 2 Custom User Fields. This is easy as follow: - -- Go to Admin -> Customize -> User Fields - -- Make then look like this: - -![user_fields](https://cloud.githubusercontent.com/assets/1385470/10153953/ecc5375a-6637-11e5-81a7-727deec3e41a.png) - - -After this go to Settings -> Users -> `public user custom fields` and add the custom fields who hold sig info, like this: - -![public_fields](https://cloud.githubusercontent.com/assets/1385470/10153952/ecc38392-6637-11e5-9353-86e1832c2a1f.png) - -PS.: This can change if you have another user fields enabled. Maybe we get to set this by field name someday. - - ## Installation -Now you proceed with a normal [installation of a plugin](https://meta.discourse.org/t/install-a-plugin/19157?u=falco). +Proceed with a normal [installation of a plugin](https://meta.discourse.org/t/install-a-plugin/19157?u=falco). ## After Installation diff --git a/assets/javascripts/discourse/templates/connectors/post-after-cooked/signature.hbs b/assets/javascripts/discourse/templates/connectors/post-after-cooked/signature.hbs index 2b4ea98..9d999bc 100644 --- a/assets/javascripts/discourse/templates/connectors/post-after-cooked/signature.hbs +++ b/assets/javascripts/discourse/templates/connectors/post-after-cooked/signature.hbs @@ -1,8 +1,6 @@ -{{#if Discourse.SiteSettings.signatures_enabled}} - {{#if user_show_signatures}} - {{#if user_signature}} -
- - {{/if}} +{{#if showSignatures}} + {{#if user_signature_url}} +
+ {{/if}} {{/if}} diff --git a/assets/stylesheets/common/signatures.scss b/assets/stylesheets/common/signatures.scss new file mode 100644 index 0000000..e69de29 diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 9e127df..43db2bb 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1,5 +1,3 @@ en: site_settings: signatures_enabled: "Enable user-made signatures below posts?" - signatures_user_optin: "User field that contains the show signatures user option, like: signatures-view" - signatures_user_signature: "User field that contains the signature URL, like: signatures-image-url" diff --git a/config/settings.yml b/config/settings.yml index 2500a10..cc6e0d2 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -2,9 +2,3 @@ plugins: signatures_enabled: default: true client: true - signatures_user_optin: - default: signatures-view - client: true - signatures_user_signature: - default: signatures-image-url - client: true diff --git a/plugin.rb b/plugin.rb index 359a2fd..5be56a8 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,17 +1,35 @@ # name: discourse-signatures # about: A plugin to get that nostalgia signatures in Discourse Foruns -# version: 0.0.1 +# version: 0.1.0 # author: Rafael Silva # url: https://github.com/xfalcox/discourse-signatures enabled_site_setting :signatures_enabled +DiscoursePluginRegistry.serialized_current_user_fields << "see_signatures" +DiscoursePluginRegistry.serialized_current_user_fields << "signature_url" after_initialize do + User.register_custom_field_type('see_signatures', :boolean) + User.register_custom_field_type('signature_url', :text) - if SiteSetting.signatures_enabled && SiteSetting.signatures_user_signature.present? && SiteSetting.signatures_user_optin.present? then - add_to_serializer(:post, :user_signature, false) { user_custom_fields["user_field_#{(UserField.find_by name: SiteSetting.signatures_user_signature).id}"] } - add_to_serializer(:post, :user_show_signatures, false) { user_custom_fields["user_field_#{(UserField.find_by name: SiteSetting.signatures_user_optin).id}"] } + if SiteSetting.signatures_enabled then + add_to_serializer(:post, :user_signature_url, false) { + object.user.custom_fields['signature_url'] + } + + # I guess this should be the default @ discourse. PR maybe? + add_to_serializer(:user, :custom_fields, false) { + if object.custom_fields == nil then + {} + else + object.custom_fields + end + } end 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"