mirror of
https://github.com/discourse/discourse-signatures.git
synced 2025-12-12 01:45:34 +00:00
DEV: Introduce syntax_tree for ruby formatting (#36)
This commit is contained in:
parent
625de74642
commit
8e3dcb97c1
9
.github/workflows/plugin-linting.yml
vendored
9
.github/workflows/plugin-linting.yml
vendored
@ -55,3 +55,12 @@ jobs:
|
|||||||
- name: Rubocop
|
- name: Rubocop
|
||||||
if: ${{ !cancelled() }}
|
if: ${{ !cancelled() }}
|
||||||
run: bundle exec rubocop .
|
run: bundle exec rubocop .
|
||||||
|
|
||||||
|
- name: Syntax Tree
|
||||||
|
if: ${{ !cancelled() }}
|
||||||
|
run: |
|
||||||
|
if test -f .streerc; then
|
||||||
|
bundle exec stree check Gemfile $(git ls-files '*.rb') $(git ls-files '*.rake')
|
||||||
|
else
|
||||||
|
echo "Stree config not detected for this repository. Skipping."
|
||||||
|
fi
|
||||||
|
|||||||
6
.github/workflows/plugin-tests.yml
vendored
6
.github/workflows/plugin-tests.yml
vendored
@ -80,7 +80,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Get yarn cache directory
|
- name: Get yarn cache directory
|
||||||
id: yarn-cache-dir
|
id: yarn-cache-dir
|
||||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Yarn cache
|
- name: Yarn cache
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
@ -130,7 +130,7 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
if [ 0 -lt $(find plugins/${{ github.event.repository.name }}/spec -type f -name "*.rb" 2> /dev/null | wc -l) ]; then
|
if [ 0 -lt $(find plugins/${{ github.event.repository.name }}/spec -type f -name "*.rb" 2> /dev/null | wc -l) ]; then
|
||||||
echo "::set-output name=files_exist::true"
|
echo "files_exist=true" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Plugin RSpec
|
- name: Plugin RSpec
|
||||||
@ -142,7 +142,7 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
if [ 0 -lt $(find plugins/${{ github.event.repository.name }}/test/javascripts -type f \( -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then
|
if [ 0 -lt $(find plugins/${{ github.event.repository.name }}/test/javascripts -type f \( -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then
|
||||||
echo "::set-output name=files_exist::true"
|
echo "files_exist=true" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Plugin QUnit
|
- name: Plugin QUnit
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
inherit_gem:
|
inherit_gem:
|
||||||
rubocop-discourse: default.yml
|
rubocop-discourse: stree-compat.yml
|
||||||
|
|||||||
1
Gemfile
1
Gemfile
@ -4,4 +4,5 @@ source "https://rubygems.org"
|
|||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
gem "rubocop-discourse"
|
gem "rubocop-discourse"
|
||||||
|
gem "syntax_tree"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -6,6 +6,7 @@ GEM
|
|||||||
parallel (1.22.1)
|
parallel (1.22.1)
|
||||||
parser (3.1.2.1)
|
parser (3.1.2.1)
|
||||||
ast (~> 2.4.1)
|
ast (~> 2.4.1)
|
||||||
|
prettier_print (1.2.0)
|
||||||
rainbow (3.1.1)
|
rainbow (3.1.1)
|
||||||
regexp_parser (2.6.0)
|
regexp_parser (2.6.0)
|
||||||
rexml (3.2.5)
|
rexml (3.2.5)
|
||||||
@ -27,6 +28,8 @@ GEM
|
|||||||
rubocop-rspec (2.13.2)
|
rubocop-rspec (2.13.2)
|
||||||
rubocop (~> 1.33)
|
rubocop (~> 1.33)
|
||||||
ruby-progressbar (1.11.0)
|
ruby-progressbar (1.11.0)
|
||||||
|
syntax_tree (5.1.0)
|
||||||
|
prettier_print (>= 1.2.0)
|
||||||
unicode-display_width (2.3.0)
|
unicode-display_width (2.3.0)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
@ -39,6 +42,7 @@ PLATFORMS
|
|||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
rubocop-discourse
|
rubocop-discourse
|
||||||
|
syntax_tree
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
2.3.10
|
2.3.10
|
||||||
|
|||||||
33
plugin.rb
33
plugin.rb
@ -14,43 +14,46 @@ DiscoursePluginRegistry.serialized_current_user_fields << "signature_url"
|
|||||||
DiscoursePluginRegistry.serialized_current_user_fields << "signature_raw"
|
DiscoursePluginRegistry.serialized_current_user_fields << "signature_raw"
|
||||||
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
User.register_custom_field_type('see_signatures', :boolean)
|
User.register_custom_field_type("see_signatures", :boolean)
|
||||||
User.register_custom_field_type('signature_url', :text)
|
User.register_custom_field_type("signature_url", :text)
|
||||||
User.register_custom_field_type('signature_raw', :text)
|
User.register_custom_field_type("signature_raw", :text)
|
||||||
|
|
||||||
# add to class and serializer to allow for default value for the setting
|
# add to class and serializer to allow for default value for the setting
|
||||||
add_to_class(:user, :see_signatures) do
|
add_to_class(:user, :see_signatures) do
|
||||||
if custom_fields['see_signatures'] != nil
|
if custom_fields["see_signatures"] != nil
|
||||||
custom_fields['see_signatures']
|
custom_fields["see_signatures"]
|
||||||
else
|
else
|
||||||
SiteSetting.signatures_visible_by_default
|
SiteSetting.signatures_visible_by_default
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
add_to_serializer(:user, :see_signatures) do
|
add_to_serializer(:user, :see_signatures) { object.see_signatures }
|
||||||
object.see_signatures
|
|
||||||
end
|
|
||||||
|
|
||||||
register_editable_user_custom_field [:see_signatures, :signature_url, :signature_raw]
|
register_editable_user_custom_field %i[see_signatures signature_url signature_raw]
|
||||||
|
|
||||||
allow_public_user_custom_field :signature_cooked
|
allow_public_user_custom_field :signature_cooked
|
||||||
allow_public_user_custom_field :signature_url
|
allow_public_user_custom_field :signature_url
|
||||||
|
|
||||||
add_to_serializer(:post, :user_signature) do
|
add_to_serializer(:post, :user_signature) do
|
||||||
if SiteSetting.signatures_advanced_mode
|
if SiteSetting.signatures_advanced_mode
|
||||||
object.user.custom_fields['signature_cooked'] if object.user
|
object.user.custom_fields["signature_cooked"] if object.user
|
||||||
else
|
else
|
||||||
object.user.custom_fields['signature_url'] if object.user
|
object.user.custom_fields["signature_url"] if object.user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# This is the code responsible for cooking a new advanced mode sig on user update
|
# This is the code responsible for cooking a new advanced mode sig on user update
|
||||||
DiscourseEvent.on(:user_updated) do |user|
|
DiscourseEvent.on(:user_updated) do |user|
|
||||||
if SiteSetting.signatures_enabled? && SiteSetting.signatures_advanced_mode && user.custom_fields['signature_raw']
|
if SiteSetting.signatures_enabled? && SiteSetting.signatures_advanced_mode &&
|
||||||
cooked_sig = PrettyText.cook(user.custom_fields['signature_raw'], omit_nofollow: user.has_trust_level?(TrustLevel[3]) && !SiteSetting.tl3_links_no_follow)
|
user.custom_fields["signature_raw"]
|
||||||
|
cooked_sig =
|
||||||
|
PrettyText.cook(
|
||||||
|
user.custom_fields["signature_raw"],
|
||||||
|
omit_nofollow: user.has_trust_level?(TrustLevel[3]) && !SiteSetting.tl3_links_no_follow,
|
||||||
|
)
|
||||||
# avoid infinite recursion
|
# avoid infinite recursion
|
||||||
if cooked_sig != user.custom_fields['signature_cooked']
|
if cooked_sig != user.custom_fields["signature_cooked"]
|
||||||
user.custom_fields['signature_cooked'] = cooked_sig
|
user.custom_fields["signature_cooked"] = cooked_sig
|
||||||
user.save
|
user.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user