Skip to content

Commit

Permalink
Improve javascript files
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Dec 25, 2024
1 parent b1dc4eb commit 5cdc10e
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 17 deletions.
25 changes: 20 additions & 5 deletions docs/api/javascript/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,39 @@ Your app needs standard script or old browser compatibility

* It's an [IIFE](https://developer.mozilla.org/en-US/docs/Glossary/IIFE) file meant to be loaded as is, directly in your
production pages and without any further processing
* Minified (~2k) and polyfilled to work also with quite old browsers
* Minified (~3k)

[!file](/gem/javascripts/pagy.min.js)

```ruby
script_path = Pagy.root.join('javascripts', 'pagy.min.js')
```

+++ `pagy.min.js.map`
+++ `pagy.js`
!!! success
Developer version: plain Javascript to use for debugging with its `pagy.js.map`
!!!

* It's an [IIFE](https://developer.mozilla.org/en-US/docs/Glossary/IIFE) file meant to be loaded as is, directly in your
production pages and without any further processing
* Minified (~2k) and polyfilled to work also with quite old browsers

[!file](/gem/javascripts/pagy.js)

```ruby
script_path = Pagy.root.join('javascripts', 'pagy.js')
```

+++ `pagy.js.map`

!!! success
You need to debug the javascript helpers while using the `pagy.min.js` file
You need to debug the javascript helpers while using the `pagy.js` file
!!!

[!file](/gem/javascripts/pagy.min.js.map)
[!file](/gem/javascripts/pagy.js.map)

```ruby
script_path = Pagy.root.join('javascripts', 'pagy.min.js.map')
script_path = Pagy.root.join('javascripts', 'pagy.js.map')
```

+++
Expand Down
2 changes: 1 addition & 1 deletion gem/apps/keyset_for_ui.ru
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class PagyKeyset < Sinatra::Base
<html>
<head>
<title>Pagy Keyset For UI App</title>
<script src="javascripts/pagy.min.js"></script>
<script src="javascripts/pagy.js"></script>
<script>
window.addEventListener("load", Pagy.init);
</script>
Expand Down
144 changes: 144 additions & 0 deletions gem/javascripts/pagy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions gem/javascripts/pagy.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/build
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ jdir="$root/gem/javascripts"

echo 'Generating javascript files'
bun build ./pagy.ts --target=node --no-bundle --outfile=$jdir/pagy.mjs
echo 'export default Pagy;' >> $jdir/pagy.mjs

bun build ./pagy.min.js --target=browser --minify --sourcemap=linked --outdir=$jdir
bun build ./pagy.js --target=browser --minify --outfile=$jdir/pagy.min.js
sed -i "0,/var ./{s/var ./window.Pagy/}" $jdir/pagy.min.js

bun build ./pagy.js --target=browser --sourcemap=linked --outdir=$jdir
sed -i "0,/var Pagy/{s/var Pagy/window.Pagy/}" $jdir/pagy.js
3 changes: 1 addition & 2 deletions src/pagy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface Sequels {readonly [width:string]:(string | number)[]}
interface LabelSequels {readonly [width:string]:string[]}
interface NavJsElement extends Element {pagyRender():void}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const Pagy = (() => {
const keysetSupport = 'sessionStorage' in window && 'BroadcastChannel' in window;
let sS: Storage, sync: BroadcastChannel, tabId: number;
Expand Down Expand Up @@ -202,5 +203,3 @@ const Pagy = (() => {
}
};
})();

export default Pagy;
7 changes: 5 additions & 2 deletions test/pagy/version_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
it 'defines the same version in javascripts/pagy.min.js' do
_(Pagy.root.join('javascripts', 'pagy.min.js').read).must_match "version:\"#{Pagy::VERSION}\","
end
it 'defines the same version in src/pagy.min.js.map' do
_(Pagy.root.join('javascripts', 'pagy.min.js.map').read).must_match "version: \\\"#{Pagy::VERSION}\\\","
it 'defines the same version in src/pagy.js' do
_(Pagy.root.join('javascripts', 'pagy.js').read).must_match "version: \"#{Pagy::VERSION}\","
end
it 'defines the same version in src/pagy.js.map' do
_(Pagy.root.join('javascripts', 'pagy.js.map').read).must_match "version: \\\"#{Pagy::VERSION}\\\","
end
it 'defines the same version in src/pagy.mjs' do
_(Pagy.root.join('javascripts', 'pagy.mjs').read).must_match "version: \"#{Pagy::VERSION}\","
Expand Down

0 comments on commit 5cdc10e

Please sign in to comment.