webring-rails 1.3.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb7c45a7911e93d8ba099c52ab12aa3552007ade35aee285cadb4adfa2eb0fb2
4
- data.tar.gz: 87c041e80ac5729486e4a1d479401255b4def0995e96e0f0e0d4773d8109f6ad
3
+ metadata.gz: 9f2abb7d64673f6596274eaeb143aa6378f0ce099a86880765a10ba0c951a9be
4
+ data.tar.gz: c5ad3ea3677093b17e271784910c47c57b3a3f45b3f222cd0ca736bbfca4ab8a
5
5
  SHA512:
6
- metadata.gz: a106e56ff61948867ec07e2cb29e3d7c547ee83b5974b9f7823c229f8d220bafe44d9f8e45de1c7b0fa6d44ed226730c22e54c10ceddb57fd700a7f0dc2b2707
7
- data.tar.gz: c5084e377d1a15bbcbe3a3fd72ab421b8aadb7f8fcfa23ddd99f3150a747563e2ef61f59dc77fc598b02cb009ff295e730e113c87e5758a7ab91e4a9f0d23ec6
6
+ metadata.gz: 18c794c278923c41f060667a806d3a5968e5b05f9e133c989817c881980939568c9aacccffc63b349fbcd6e4475f5fe94e27be8b8253bee41bf3d0aeb21b84a9
7
+ data.tar.gz: d83a28c05cedaec133e26c4936b33a3c786bf276ade1318665cc8ea2542bf01ea9e8180fdb32a92a83a9f3ce5ac9b92399efad4b7ea2e01e1877ae87050d8c09
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Webring for Rails
4
4
 
5
- Webring for Rails (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.
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,29 +36,64 @@
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: Prev',
79
+ text: ${FULL_TEXT_DEFAULTS.prev.default}`,
80
+ text_enforced: FULL_TEXT_DEFAULTS.prev.enforced,
44
81
  title: 'Previous site',
45
82
  path: 'previous',
46
83
  additionalClass: 'prev-btn'
47
84
  },
48
85
  random: {
49
86
  symbol: logoSvg(23, 23),
50
- text: `${logoSvg(20, 20, "margin-right: 4px; margin-top: 1px;")} Random`,
87
+ text: `${logoSvg(20, 20, "margin-right: 4px; margin-top: 1px;")} ${FULL_TEXT_DEFAULTS.random.default}`,
88
+ text_enforced: FULL_TEXT_DEFAULTS.random.enforced,
51
89
  title: 'Random site',
52
90
  path: 'random',
53
91
  additionalClass: 'random-btn'
54
92
  },
55
93
  next: {
56
94
  symbol: '»',
57
- text: 'Next »',
95
+ text: `${FULL_TEXT_DEFAULTS.next.default} »`,
96
+ text_enforced: FULL_TEXT_DEFAULTS.next.enforced,
58
97
  title: 'Next site',
59
98
  path: 'next',
60
99
  additionalClass: 'next-btn'
@@ -142,6 +181,7 @@
142
181
  font-weight: 600;
143
182
  }
144
183
  .webring-nav a.webring-btn {
184
+ text-wrap: nowrap;
145
185
  color: #000000;
146
186
  font-weight: 600;
147
187
  background-color: #ffffff;
@@ -184,6 +224,12 @@
184
224
  const stylesType = script.getAttribute('data-styles') || WIDGET_CONFIG.DEFAULT_STYLE_TYPE;
185
225
  const stylesOption = WIDGET_CONFIG.VALID_STYLE_TYPES.includes(stylesType) ? stylesType : WIDGET_CONFIG.DEFAULT_STYLE_TYPE;
186
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
+
187
233
  if (!memberUid) {
188
234
  console.error('Webring Widget: Missing data-member-uid attribute on script tag.');
189
235
  return;
@@ -204,10 +250,27 @@
204
250
  return;
205
251
  }
206
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
+
207
270
  // Navigation links
208
271
  const config = WIDGET_TYPE_CONFIG[widgetType];
209
272
  const linkElements = config.actions.map(action => {
210
- const actionConfig = NAVIGATION_ACTIONS[action];
273
+ const actionConfig = customTexts[action] || NAVIGATION_ACTIONS[action];
211
274
 
212
275
  // Logo-only block
213
276
  if (action === 'logoOnly') {
@@ -220,8 +283,12 @@
220
283
 
221
284
  // One-way type case
222
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
+
223
290
  label = buttonText
224
- ? `<span class="webring-logo-inline">${logoSvg(20, 20)}</span> ${actionConfig.text}`
291
+ ? `<span class="webring-logo-inline">${logoSvg(20, 20)}</span> ${buttonTextContent} »`
225
292
  : `<span class="webring-logo-inline">${logoSvg(20, 20)}</span> ${actionConfig.symbol}`;
226
293
  }
227
294
 
@@ -229,7 +296,11 @@
229
296
  }).join('\n ');
230
297
 
231
298
  // Create widget HTML
232
- const title = config.showTitle ? '<span class="webring-title">Ruby Webring</span>' : '';
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>` : '';
233
304
  container.innerHTML = `
234
305
  <div class="webring-nav" data-widget-type="${widgetType}" data-button-text="${buttonText}">
235
306
  ${title}
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Webring
2
- VERSION = '1.3.1'.freeze
2
+ VERSION = '1.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webring-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Shkoda