Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate with Prism API plugin #72

Merged
merged 5 commits into from
Sep 26, 2023
Merged

Conversation

timja
Copy link
Member

@timja timja commented May 23, 2022

Fixes #68

Requires jenkinsci/prism-api-plugin#107

I've tested this pretty heavily, it was quite fiddly but as far as I can tell it's working nicely

Testing done

By going to the design library views and clicking through them

Note: Design library is quite a complex integration for this as it loads sources dynamically after Prism runs in some cases so it has some extra hardening to make it more reliable, simple integrations should be a lot easier

Tested with:

  • Light
  • Dark
  • System - light and dark
  • Live theme switching
  • Selecting a non default theme and seeing it used instead

Todo:

Currently you need to select the theme in your system configuration, screenshot is using 'Tomorrow Night'

image

cc @janfaracik / @uhafner

<script type="text/javascript" src="${resURL}/plugin/prism-api/js/prism-clike.js"/>
<script type="text/javascript" src="${resURL}/plugin/prism-api/js/prism-css.js"/>
<script type="text/javascript" src="${resURL}/plugin/prism-api/js/prism-java.min.js"/>
<link type="text/css" rel="stylesheet" href="${resURL}/plugin/prism-api/css/${it.themeCssFileName}"/>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uhafner this caught me out, it's not defined in the prism.jelly but in the SourceCodeViewModel https://github.com/jenkinsci/prism-api-plugin/blob/main/src/main/resources/io/jenkins/plugins/prism/SourceCodeViewModel/index.jelly#L10

seemed a bit strange that the plugin didn't load it, some sort of invoke static could probably be used to avoid having to define the getter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would make sense to autoload the theme somehow in the main jelly file. Since the warnings plugin is the only component so far that uses the plugin it was not yet necessary up to now. I'm not sure how to store that information on the JS side though. I think when we make the theming customizable via the theme manager plugin we should change that...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timja timja marked this pull request as ready for review August 20, 2023 14:58
@timja timja requested a review from a team as a code owner August 20, 2023 14:58
pom.xml Outdated Show resolved Hide resolved
Comment on lines +93 to +101
<!-- For some reason need to explicitly depend on commons-text-api and commons-lang3-api for plugin-util-api to load -->
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>commons-text-api</artifactId>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>commons-lang3-api</artifactId>
</dependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I use prism 1.29.0-8 as local dependency I do not see such a problem. Where exactly did you see the problem? I've seen that in the BOM builds Mark also had this problem.

Suggested change
<!-- For some reason need to explicitly depend on commons-text-api and commons-lang3-api for plugin-util-api to load -->
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>commons-text-api</artifactId>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>commons-lang3-api</artifactId>
</dependency>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsure but lots of people were complaining about it for checks-api, and I added them there too:
jenkinsci/checks-api-plugin#233

Although at least in checks api it actually used those dependencies.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails injected tests from maven hpi plugin, if you try locally you will get:

[ERROR] Failures:
[ERROR]   InjectedTest.testPluginActive While testing design-library, plugin-util-api failed to start
Caused by: java.io.IOException: Failed to load: Plugin Utilities API Plugin (plugin-util-api 3.3.0)
 - Plugin is missing: commons-text-api (1.10.0-36.vc008c8fcda_7b_)
 - Plugin is missing: commons-lang3-api (3.12.0-36.vd97de6465d5b_)
	at hudson.PluginWrapper.resolvePluginDependencies(PluginWrapper.java:988)
	at hudson.PluginManager$2$1$1.run(PluginManager.java:555)
	at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:177)
	at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:305)
	at jenkins.model.Jenkins$5.runTask(Jenkins.java:1170)
	at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:221)
	at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:120)
	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)

pom.xml Outdated Show resolved Hide resolved
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
setPrismBackgroundVariable()
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be sufficient to call Prism.highlightElement(element) when the user changes the theme?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I've added some comments to explain more but the above isn't for the elements it's so that the copy to clipboard section matches which doesn't use prism:
image

Comment on lines +10 to +12
// On the inputs page the preview markup link adds a hash to the url which breaks the regex extraction
const strippedHash = window.location.href.replace('#', '')
const componentName = strippedHash.match(/.+design-library\/(.+)$/)[1]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor bug introduced in #281 cc @mawinter69

at least locally in hpi:run I can't reproduce it on weekly.ci.jenkins.io

If I click it locally I get a # fragment added to the url and the page scrolled to the top and then if I refresh the page none of the examples load

On weekly it live updates in place though with no issue

@timja timja merged commit eae3179 into jenkinsci:master Sep 26, 2023
16 checks passed
@timja timja deleted the prism-api-integration branch September 26, 2023 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code blocks should use user's theme
2 participants