Skip to content

Commit

Permalink
chore: replace plugin wrapper with plugin context (#136)
Browse files Browse the repository at this point in the history
### What this PR does?
替换插件中对于 PluginWrapper 的引用,这是已经过时的引用,这将在后续被移除

```release-note
None
```
  • Loading branch information
guqing authored Jul 4, 2024
1 parent ec513c2 commit 35ab602
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package run.halo.comment.widget;

import java.util.Properties;
import lombok.RequiredArgsConstructor;
import org.pf4j.PluginWrapper;
import org.springframework.stereotype.Component;
import org.springframework.util.PropertyPlaceholderHelper;
import org.thymeleaf.context.ITemplateContext;
import org.thymeleaf.model.IModel;
import org.thymeleaf.model.IModelFactory;
import org.thymeleaf.processor.element.IElementModelStructureHandler;
import reactor.core.publisher.Mono;
import run.halo.app.plugin.PluginContext;
import run.halo.app.theme.dialect.TemplateHeadProcessor;

import java.util.Properties;

@Component
@RequiredArgsConstructor
public class CommentWidgetHeadProcessor implements TemplateHeadProcessor {

static final PropertyPlaceholderHelper PROPERTY_PLACEHOLDER_HELPER = new PropertyPlaceholderHelper("${", "}");

private final PluginWrapper pluginWrapper;
private final PluginContext pluginContext;

@Override
public Mono<Void> process(ITemplateContext context, IModel model,
Expand All @@ -32,13 +31,13 @@ public Mono<Void> process(ITemplateContext context, IModel model,
private String commentWidgetScript() {

final Properties properties = new Properties();
properties.setProperty("version", pluginWrapper.getDescriptor().getVersion());
properties.setProperty("version", pluginContext.getVersion());

return PROPERTY_PLACEHOLDER_HELPER.replacePlaceholders("""
<!-- plugin-comment-widget start -->
<script src="/plugins/PluginCommentWidget/assets/static/comment-widget.iife.js?version=${version}"></script>
<link rel="stylesheet" href="/plugins/PluginCommentWidget/assets/static/style.css?version=${version}" />
<!-- plugin-comment-widget end -->
""", properties);
<!-- plugin-comment-widget start -->
<script src="/plugins/PluginCommentWidget/assets/static/comment-widget.iife.js?version=${version}"></script>
<link rel="stylesheet" href="/plugins/PluginCommentWidget/assets/static/style.css?version=${version}" />
<!-- plugin-comment-widget end -->
""", properties);
}
}
14 changes: 3 additions & 11 deletions src/main/java/run/halo/comment/widget/CommentWidgetPlugin.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
package run.halo.comment.widget;

import org.pf4j.PluginWrapper;
import org.springframework.stereotype.Component;
import run.halo.app.plugin.BasePlugin;
import run.halo.app.plugin.PluginContext;

/**
* @author ryanwang
* @since 2.0.0
*/
@Component
public class CommentWidgetPlugin extends BasePlugin {
public CommentWidgetPlugin(PluginWrapper wrapper) {
super(wrapper);
}

@Override
public void start() {
}

@Override
public void stop() {
public CommentWidgetPlugin(PluginContext pluginContext) {
super(pluginContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.pf4j.PluginWrapper;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.PropertyPlaceholderHelper;
import org.thymeleaf.context.ITemplateContext;
import org.thymeleaf.model.IAttribute;
import org.thymeleaf.model.IProcessableElementTag;
import org.thymeleaf.processor.element.IElementTagStructureHandler;
import run.halo.app.plugin.SettingFetcher;
import run.halo.app.plugin.PluginContext;
import run.halo.app.theme.dialect.CommentWidget;

/**
Expand All @@ -27,7 +26,7 @@
public class DefaultCommentWidget implements CommentWidget {
static final PropertyPlaceholderHelper PROPERTY_PLACEHOLDER_HELPER = new PropertyPlaceholderHelper("${", "}");

private final PluginWrapper pluginWrapper;
private final PluginContext pluginContext;
private final SettingConfigGetter settingConfigGetter;

@Override
Expand Down Expand Up @@ -57,7 +56,7 @@ private String commentHtml(IAttribute groupAttribute, IAttribute kindAttribute,

final Properties properties = new Properties();

properties.setProperty("version", pluginWrapper.getDescriptor().getVersion());
properties.setProperty("version", pluginContext.getVersion());
properties.setProperty("group", group);
properties.setProperty("kind", kindAttribute.getValue());
properties.setProperty("name", nameAttribute.getValue());
Expand Down

0 comments on commit 35ab602

Please sign in to comment.