webring-rails 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/app/assets/javascripts/webring/widget.js +100 -17
- data/app/controllers/webring/widget_controller.rb +12 -0
- data/lib/generators/webring/custom_widget_controller/templates/custom_widget_controller.rb +11 -0
- data/lib/webring/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f2abb7d64673f6596274eaeb143aa6378f0ce099a86880765a10ba0c951a9be
|
4
|
+
data.tar.gz: c5ad3ea3677093b17e271784910c47c57b3a3f45b3f222cd0ca736bbfca4ab8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18c794c278923c41f060667a806d3a5968e5b05f9e133c989817c881980939568c9aacccffc63b349fbcd6e4475f5fe94e27be8b8253bee41bf3d0aeb21b84a9
|
7
|
+
data.tar.gz: d83a28c05cedaec133e26c4936b33a3c786bf276ade1318665cc8ea2542bf01ea9e8180fdb32a92a83a9f3ce5ac9b92399efad4b7ea2e01e1877ae87050d8c09
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-

|
2
2
|
|
3
3
|
# Webring for Rails
|
4
4
|
|
5
|
-
Webring for Rails (
|
5
|
+
[Webring for Rails (webring-rails)](https://github.com/lstpsche/webring-rails) is a flexible engine for creating and managing a webring system in your Ruby on Rails application. A webring is a collection of websites linked together in a circular structure, allowing visitors to navigate from one site to another.
|
6
6
|
|
7
7
|
## Features
|
8
8
|
|
@@ -22,6 +22,10 @@
|
|
22
22
|
* - full: Apply all styles (default)
|
23
23
|
* - layout: Only layout styles, no visual design
|
24
24
|
* - none: No styles applied
|
25
|
+
* - data-prev-text="Custom Text": Sets custom text for the "previous" button. Default: "« Prev"
|
26
|
+
* - data-random-text="Custom Text": Sets custom text for the "random" button (keeps the logo). Default: "Random"
|
27
|
+
* - data-next-text="Custom Text": Sets custom text for the "next" button. Default: "Next »"
|
28
|
+
* - data-widget-text="Custom Text": Sets custom text for the widget title. Default: "Webring"
|
25
29
|
*/
|
26
30
|
|
27
31
|
(function() {
|
@@ -32,36 +36,73 @@
|
|
32
36
|
DEFAULT_TARGET_ID: 'webring-widget',
|
33
37
|
STYLE_ID: 'webring-widget-styles',
|
34
38
|
VALID_STYLE_TYPES: ['full', 'layout', 'none'],
|
35
|
-
DEFAULT_STYLE_TYPE: 'full'
|
39
|
+
DEFAULT_STYLE_TYPE: 'full',
|
40
|
+
DEFAULT_TEXTS: {
|
41
|
+
PREV: '« Prev',
|
42
|
+
RANDOM: 'Random',
|
43
|
+
NEXT: 'Next »',
|
44
|
+
WIDGET: 'Webring'
|
45
|
+
}
|
46
|
+
};
|
47
|
+
|
48
|
+
// Default text configurations
|
49
|
+
const TEXT_DEFAULTS = {
|
50
|
+
prev: { default: '« Prev', enforced: false },
|
51
|
+
random: { default: 'Random', enforced: false },
|
52
|
+
next: { default: 'Next »', enforced: false },
|
53
|
+
widgetTitle: { default: 'Webring', enforced: false }
|
36
54
|
};
|
37
55
|
|
56
|
+
// These defaults will be provided by the widget_controller
|
57
|
+
const PROVIDED_TEXT_DEFAULTS = "<<REPLACE_ME_TEXT_DEFAULTS>>";
|
58
|
+
|
59
|
+
// Parse the provided defaults JSON string
|
60
|
+
const parsedProvidedDefaults =
|
61
|
+
PROVIDED_TEXT_DEFAULTS !== "<<REPLACE_ME_TEXT_DEFAULTS>>"
|
62
|
+
? (typeof PROVIDED_TEXT_DEFAULTS === 'string' ? JSON.parse(PROVIDED_TEXT_DEFAULTS) : PROVIDED_TEXT_DEFAULTS)
|
63
|
+
: {};
|
64
|
+
|
65
|
+
// Merge defaults with provided defaults, with provided taking priority
|
66
|
+
const FULL_TEXT_DEFAULTS = Object.keys(TEXT_DEFAULTS).reduce((acc, key) => {
|
67
|
+
acc[key] = {
|
68
|
+
default: parsedProvidedDefaults[key]?.default || TEXT_DEFAULTS[key].default,
|
69
|
+
enforced: parsedProvidedDefaults[key]?.enforced || TEXT_DEFAULTS[key].enforced
|
70
|
+
};
|
71
|
+
return acc;
|
72
|
+
}, {});
|
73
|
+
|
38
74
|
const logoSvg = (width = 20, height = 20, style = "") => `<<REPLACE_ME_LOGO_SVG>>`;
|
39
75
|
|
40
76
|
const NAVIGATION_ACTIONS = {
|
41
77
|
prev: {
|
42
78
|
symbol: '«',
|
43
|
-
text:
|
79
|
+
text: `« ${FULL_TEXT_DEFAULTS.prev.default}`,
|
80
|
+
text_enforced: FULL_TEXT_DEFAULTS.prev.enforced,
|
44
81
|
title: 'Previous site',
|
45
|
-
path: 'previous'
|
82
|
+
path: 'previous',
|
83
|
+
additionalClass: 'prev-btn'
|
46
84
|
},
|
47
85
|
random: {
|
48
|
-
symbol: logoSvg(
|
49
|
-
text: `${logoSvg(20, 20, "margin-right: 4px; margin-top: 1px;")}
|
86
|
+
symbol: logoSvg(23, 23),
|
87
|
+
text: `${logoSvg(20, 20, "margin-right: 4px; margin-top: 1px;")} ${FULL_TEXT_DEFAULTS.random.default}`,
|
88
|
+
text_enforced: FULL_TEXT_DEFAULTS.random.enforced,
|
50
89
|
title: 'Random site',
|
51
90
|
path: 'random',
|
52
91
|
additionalClass: 'random-btn'
|
53
92
|
},
|
54
93
|
next: {
|
55
94
|
symbol: '»',
|
56
|
-
text:
|
95
|
+
text: `${FULL_TEXT_DEFAULTS.next.default} »`,
|
96
|
+
text_enforced: FULL_TEXT_DEFAULTS.next.enforced,
|
57
97
|
title: 'Next site',
|
58
|
-
path: 'next'
|
98
|
+
path: 'next',
|
99
|
+
additionalClass: 'next-btn'
|
59
100
|
},
|
60
101
|
logoOnly: {
|
61
|
-
symbol: logoSvg(
|
62
|
-
text:
|
63
|
-
|
64
|
-
|
102
|
+
symbol: logoSvg(23, 23),
|
103
|
+
text: logoSvg(23, 23),
|
104
|
+
path: '',
|
105
|
+
additionalClass: 'logo-only'
|
65
106
|
}
|
66
107
|
};
|
67
108
|
|
@@ -104,7 +145,7 @@
|
|
104
145
|
text-decoration: none;
|
105
146
|
}
|
106
147
|
.webring-nav a.webring-btn.random-btn {
|
107
|
-
padding: 6px
|
148
|
+
padding: 6px 8px 6px 8px;
|
108
149
|
}
|
109
150
|
.webring-nav .logo-only {
|
110
151
|
padding: 8px 3px 6px 3px;
|
@@ -121,6 +162,16 @@
|
|
121
162
|
margin-right: 6px;
|
122
163
|
margin-top: 1px;
|
123
164
|
}
|
165
|
+
/* no-text prev button */
|
166
|
+
.webring-nav[data-button-text="false"] a.webring-btn.prev-btn {
|
167
|
+
padding-top: 5px;
|
168
|
+
padding-right: 12.5px;
|
169
|
+
}
|
170
|
+
/* no-text next button */
|
171
|
+
.webring-nav[data-button-text="false"] a.webring-btn.next-btn {
|
172
|
+
padding-top: 5px;
|
173
|
+
padding-left: 12.5px;
|
174
|
+
}
|
124
175
|
`,
|
125
176
|
design: `
|
126
177
|
.webring-nav[data-widget-type="full"] {
|
@@ -130,6 +181,7 @@
|
|
130
181
|
font-weight: 600;
|
131
182
|
}
|
132
183
|
.webring-nav a.webring-btn {
|
184
|
+
text-wrap: nowrap;
|
133
185
|
color: #000000;
|
134
186
|
font-weight: 600;
|
135
187
|
background-color: #ffffff;
|
@@ -172,6 +224,12 @@
|
|
172
224
|
const stylesType = script.getAttribute('data-styles') || WIDGET_CONFIG.DEFAULT_STYLE_TYPE;
|
173
225
|
const stylesOption = WIDGET_CONFIG.VALID_STYLE_TYPES.includes(stylesType) ? stylesType : WIDGET_CONFIG.DEFAULT_STYLE_TYPE;
|
174
226
|
|
227
|
+
// Custom text data attributes
|
228
|
+
const prevText = script.getAttribute('data-prev-text');
|
229
|
+
const randomText = script.getAttribute('data-random-text');
|
230
|
+
const nextText = script.getAttribute('data-next-text');
|
231
|
+
const widgetText = script.getAttribute('data-widget-text');
|
232
|
+
|
175
233
|
if (!memberUid) {
|
176
234
|
console.error('Webring Widget: Missing data-member-uid attribute on script tag.');
|
177
235
|
return;
|
@@ -192,14 +250,31 @@
|
|
192
250
|
return;
|
193
251
|
}
|
194
252
|
|
253
|
+
// Apply custom texts if provided or use defaults based on enforcement settings
|
254
|
+
const customTexts = {
|
255
|
+
prev: NAVIGATION_ACTIONS.prev.text_enforced ?
|
256
|
+
{ ...NAVIGATION_ACTIONS.prev } :
|
257
|
+
(prevText ? { ...NAVIGATION_ACTIONS.prev, text: `« ${prevText}` } : NAVIGATION_ACTIONS.prev),
|
258
|
+
random: NAVIGATION_ACTIONS.random.text_enforced ?
|
259
|
+
{ ...NAVIGATION_ACTIONS.random } :
|
260
|
+
(randomText ? {
|
261
|
+
...NAVIGATION_ACTIONS.random,
|
262
|
+
text: `${logoSvg(20, 20, "margin-right: 4px; margin-top: 1px;")} ${randomText}`
|
263
|
+
} : NAVIGATION_ACTIONS.random),
|
264
|
+
next: NAVIGATION_ACTIONS.next.text_enforced ?
|
265
|
+
{ ...NAVIGATION_ACTIONS.next } :
|
266
|
+
(nextText ? { ...NAVIGATION_ACTIONS.next, text: `${nextText} »` } : NAVIGATION_ACTIONS.next),
|
267
|
+
logoOnly: NAVIGATION_ACTIONS.logoOnly
|
268
|
+
};
|
269
|
+
|
195
270
|
// Navigation links
|
196
271
|
const config = WIDGET_TYPE_CONFIG[widgetType];
|
197
272
|
const linkElements = config.actions.map(action => {
|
198
|
-
const actionConfig = NAVIGATION_ACTIONS[action];
|
273
|
+
const actionConfig = customTexts[action] || NAVIGATION_ACTIONS[action];
|
199
274
|
|
200
275
|
// Logo-only block
|
201
276
|
if (action === 'logoOnly') {
|
202
|
-
return `<div class="
|
277
|
+
return `<div class="${actionConfig.additionalClass}">${actionConfig.symbol}</div>`;
|
203
278
|
}
|
204
279
|
|
205
280
|
const url = `${baseUrl}/webring/${actionConfig.path}?source_member_uid=${memberUid}`;
|
@@ -208,8 +283,12 @@
|
|
208
283
|
|
209
284
|
// One-way type case
|
210
285
|
if (widgetType === 'one-way' && config.showLogoInButton && action === 'next') {
|
286
|
+
const buttonTextContent = NAVIGATION_ACTIONS.next.text_enforced ?
|
287
|
+
FULL_TEXT_DEFAULTS.next.default :
|
288
|
+
(nextText || customTexts.next.text.replace(' »', ''));
|
289
|
+
|
211
290
|
label = buttonText
|
212
|
-
? `<span class="webring-logo-inline">${logoSvg(20, 20)}</span> ${
|
291
|
+
? `<span class="webring-logo-inline">${logoSvg(20, 20)}</span> ${buttonTextContent} »`
|
213
292
|
: `<span class="webring-logo-inline">${logoSvg(20, 20)}</span> ${actionConfig.symbol}`;
|
214
293
|
}
|
215
294
|
|
@@ -217,9 +296,13 @@
|
|
217
296
|
}).join('\n ');
|
218
297
|
|
219
298
|
// Create widget HTML
|
220
|
-
const
|
299
|
+
const titleText = FULL_TEXT_DEFAULTS.widgetTitle.enforced ?
|
300
|
+
FULL_TEXT_DEFAULTS.widgetTitle.default :
|
301
|
+
(widgetText || FULL_TEXT_DEFAULTS.widgetTitle.default);
|
302
|
+
|
303
|
+
const title = config.showTitle ? `<span class="webring-title">${titleText}</span>` : '';
|
221
304
|
container.innerHTML = `
|
222
|
-
<div class="webring-nav" data-widget-type="${widgetType}">
|
305
|
+
<div class="webring-nav" data-widget-type="${widgetType}" data-button-text="${buttonText}">
|
223
306
|
${title}
|
224
307
|
<nav class="webring-buttons">
|
225
308
|
${linkElements}
|
@@ -19,6 +19,7 @@ module Webring
|
|
19
19
|
.root.join('app/assets/javascripts/webring/widget.js')
|
20
20
|
.read
|
21
21
|
.gsub('<<REPLACE_ME_LOGO_SVG>>', logo_svg)
|
22
|
+
.gsub('"<<REPLACE_ME_TEXT_DEFAULTS>>"', JSON.generate(text_defaults))
|
22
23
|
|
23
24
|
render js: widget_js
|
24
25
|
end
|
@@ -42,5 +43,16 @@ module Webring
|
|
42
43
|
</svg>
|
43
44
|
SVG
|
44
45
|
end
|
46
|
+
|
47
|
+
# Provide default texts for the widget
|
48
|
+
# Override this method to customize the default texts
|
49
|
+
def text_defaults
|
50
|
+
{
|
51
|
+
prev: { default: 'Prev', enforced: false },
|
52
|
+
random: { default: 'Random', enforced: false },
|
53
|
+
next: { default: 'Next', enforced: false },
|
54
|
+
widgetTitle: { default: 'Webring', enforced: false }
|
55
|
+
}
|
56
|
+
end
|
45
57
|
end
|
46
58
|
end
|
@@ -9,5 +9,16 @@ module Webring
|
|
9
9
|
Add your custom logo SVG here
|
10
10
|
SVG
|
11
11
|
end
|
12
|
+
|
13
|
+
# Override default texts for the widget
|
14
|
+
# Remove the method or call `super` to use the gem's default texts
|
15
|
+
def text_defaults
|
16
|
+
{
|
17
|
+
prev: { default: 'Prev', enforced: false },
|
18
|
+
random: { default: 'Random', enforced: false },
|
19
|
+
next: { default: 'Next', enforced: false },
|
20
|
+
widgetTitle: { default: 'Webring', enforced: false }
|
21
|
+
}
|
22
|
+
end
|
12
23
|
end
|
13
24
|
end
|
data/lib/webring/version.rb
CHANGED