easy_menu 0.5.0 → 0.6.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: 3b1e9ced377fa41ccde18eb63585c26db224c90265189c18630cf3912bb4df9f
4
- data.tar.gz: dd2dfb7d78dc212fa78c3b4f129d5ce5537fe6ef32e13677fe9506fc01b5b4e1
3
+ metadata.gz: b3dbed4f51e1a4df59bca564a8c684568b4b569bdbd416d83e9e572bf49a97ad
4
+ data.tar.gz: 5cff12c998bb96efb7c09aff77ec087a0638db79fd7721c165afa7668d85539c
5
5
  SHA512:
6
- metadata.gz: f1f95ffcbff00e46f1ba6eaef34244b86da72c97d73daf97a530b712c025457d8d9f2b6ce1aef57fa5d41fcf8f329176ec5c61530244f8fde5fd25c127edbf15
7
- data.tar.gz: 6a5f6e530e9c2da66101db87c0bab4002322aa75b8f3f9ea21c3eaeae42de23b4c2da3f74a2d854aeffdc5bc0f782fb87d93bff4b67dcbaf48a074ed56081718
6
+ metadata.gz: 7622aae3a25d009c42bc3537b63783ed0d13c094c9a671da3ebfa35229ac23e1873d093ec845baa1dd7051a824f82e8ac991eb322b8bac15265e9cc94f9d747a
7
+ data.tar.gz: d28ae089ae71cea05c2092be1d13705a58664ccb0d9b3df68b1ab5787f45559be28c17b9928c5d98f54a07d12b85f31bb52d9f5d7ffcd71ae74ed0f3d09e691f
data/README CHANGED
@@ -1,4 +1,239 @@
1
1
  # Easy Menu
2
- ## Make menus the easy way
3
2
 
4
- Supports Prototype and Jquery
3
+ Simple menu bar and dropdown DSL for Rails views.
4
+
5
+ Easy Menu provides a small Ruby DSL for building menu bars, grouped dropdowns, and menu actions in helpers or views. It ships with default styles and JavaScript behavior designed for traditional server-rendered Rails applications.
6
+
7
+ Supports Prototype and jQuery integrations used by legacy projects.
8
+
9
+ ## Features
10
+
11
+ - Ruby DSL for menu bars and dropdown menus
12
+ - Nested menu groups and separators
13
+ - Selection and disabled states
14
+ - Right and left aligned menu content
15
+ - Configurable global and per-menu behavior
16
+ - Rails engine assets (styles and JavaScript)
17
+
18
+ ## Installation
19
+
20
+ Add to your Gemfile:
21
+
22
+ ```ruby
23
+ gem 'easy_menu'
24
+ ```
25
+
26
+ Then run:
27
+
28
+ ```bash
29
+ bundle install
30
+ ```
31
+
32
+ ## Quick Start
33
+
34
+ Build a menu bar in a helper:
35
+
36
+ ```ruby
37
+ def users_menu
38
+ MenuBar.new(self) do |mb|
39
+ mb.menu_bar_item(link_to('All Users', users_path)).selected(params[:action] == 'index')
40
+ mb.menu_bar_item(link_to('Invite', new_user_invitation_path))
41
+
42
+ mb.menu('More') do |menu|
43
+ menu.menu_item(link_to('Roles', roles_path))
44
+ menu.menu_item(link_to('Permissions', permissions_path))
45
+ end
46
+ end
47
+ end
48
+ ```
49
+
50
+ Render it in a view:
51
+
52
+ ```erb
53
+ <%= users_menu %>
54
+ ```
55
+
56
+ ## Core DSL
57
+
58
+ ### MenuBar
59
+
60
+ Create a menu bar:
61
+
62
+ ```ruby
63
+ MenuBar.new(self, theme: :default_theme) do |mb|
64
+ # items
65
+ end
66
+ ```
67
+
68
+ Common methods:
69
+
70
+ - `menu_bar_item(content, options = {})`
71
+ - `menu(button_text, options = {}) { |menu| ... }`
72
+ - `group(options = {}) { |group| ... }`
73
+ - `menu_bar_content(content = nil, options = {}, &block)`
74
+ - `menu_bar_input(content, options = {})`
75
+ - `separator(options = {})`
76
+
77
+ ### Menu
78
+
79
+ Inside `menu(...)` blocks:
80
+
81
+ - `menu_item(content, options = {})`
82
+ - `group(title, options = {}) { |group| ... }`
83
+ - `menu_content(content = nil, options = {}, &block)`
84
+ - `separator(options = {})`
85
+
86
+ ### Item States
87
+
88
+ Most items support:
89
+
90
+ - `.selected(true_or_false)`
91
+ - `.disabled(true_or_false = true, click_blocker_html_options = {})`
92
+ - `.disable_when(dom_element, dom_event, js_condition, click_blocker_html_options = {})`
93
+
94
+ ## Alignment and Ordering
95
+
96
+ Menu item alignment is set on the content wrapper:
97
+
98
+ ```ruby
99
+ mb.menu_bar_item(link_to('Sign Out', destroy_user_session_path), align: :right)
100
+ ```
101
+
102
+ ### Right-Aligned Insert Strategy
103
+
104
+ Easy Menu supports two right-aligned insertion strategies:
105
+
106
+ - `:legacy_prepend` (default)
107
+ - Preserves historical float-right behavior.
108
+ - Right-aligned items are prepended internally.
109
+ - `:preserve_definition_order`
110
+ - Right-aligned items keep the same order they are declared in Ruby.
111
+ - Useful for flexbox-based layouts.
112
+
113
+ Set per menu bar:
114
+
115
+ ```ruby
116
+ MenuBar.new(self, right_aligned_insert_strategy: :preserve_definition_order) do |mb|
117
+ mb.menu_bar_item(link_to('My Account', my_account_path), align: :right)
118
+ mb.menu_bar_item(link_to('Sign Out', destroy_user_session_path), align: :right)
119
+ end
120
+ ```
121
+
122
+ Set globally:
123
+
124
+ ```ruby
125
+ MenuBar.config[:right_aligned_insert_strategy] = :preserve_definition_order
126
+ ```
127
+
128
+ ### Explicit Indexing
129
+
130
+ `index` always takes precedence over insert strategy:
131
+
132
+ ```ruby
133
+ mb.menu_bar_item(link_to('First', first_path), index: 0)
134
+ ```
135
+
136
+ ## Configuration
137
+
138
+ Configuration is available through `MenuBar.config` and defaults from `EasyMenu::Configuration::Default`.
139
+
140
+ Examples:
141
+
142
+ - Element wrappers (`:menu_bar_element`, `:menu_item_element`, ...)
143
+ - CSS class names (`:menu_bar_class`, `:menu_item_class`, ...)
144
+ - State classes (`:selected_class`, `:disabled_class`)
145
+ - Right alignment strategy (`:right_aligned_insert_strategy`)
146
+
147
+ Per-menu overrides can be passed using `config:`:
148
+
149
+ ```ruby
150
+ MenuBar.new(self, config: { menu_bar_element: :nav }) do |mb|
151
+ mb.menu_bar_item('Example')
152
+ end
153
+ ```
154
+
155
+ ## HTML Options and Data Attributes
156
+
157
+ Most wrapper/item calls accept standard HTML options:
158
+
159
+ - `id`
160
+ - `class`
161
+ - `title`
162
+ - `style`
163
+ - `data`
164
+ - `data-*` keys
165
+
166
+ ## Styling and JavaScript Notes
167
+
168
+ - The gem provides default styles (`easy_menu.css.scss`) and behavior hooks.
169
+ - `menu_bar_content_with_menu_class` defaults to `with_menu no_js`.
170
+ - The `no_js` class is meant to be removed client-side when JavaScript is active.
171
+
172
+ Projects commonly layer app-specific CSS on top of Easy Menu's baseline classes.
173
+
174
+ ## Common Patterns
175
+
176
+ ### Search Form Content in a Menu Bar
177
+
178
+ ```ruby
179
+ mb.group do |group|
180
+ group.menu_bar_content do
181
+ form_tag(search_path, method: :get) { text_field_tag(:q) }
182
+ end
183
+ group.menu_bar_item(link_to('Clear', search_path)) if params[:q].present?
184
+ end
185
+ ```
186
+
187
+ ### Grouped Dropdown Menu
188
+
189
+ ```ruby
190
+ mb.menu('Admin') do |menu|
191
+ menu.group('Users') do |group|
192
+ group.menu_item(link_to('List', users_path))
193
+ group.menu_item(link_to('Invite', new_user_invitation_path))
194
+ end
195
+
196
+ menu.separator
197
+
198
+ menu.group('System') do |group|
199
+ group.menu_item(link_to('Configuration', system_configuration_path))
200
+ end
201
+ end
202
+ ```
203
+
204
+ ## Migration Notes for Flex Layouts
205
+
206
+ If your app moved menu bars from float-based CSS to flexbox:
207
+
208
+ - Keep default `:legacy_prepend` unless you verify visual order is correct.
209
+ - Prefer `:preserve_definition_order` for flex layouts where declaration order should match render order.
210
+ - If needed, enable per-menu first, then move to global config.
211
+
212
+ ## Troubleshooting
213
+
214
+ ### Right-aligned items appear reversed
215
+
216
+ Use:
217
+
218
+ ```ruby
219
+ MenuBar.new(self, right_aligned_insert_strategy: :preserve_definition_order)
220
+ ```
221
+
222
+ ### Unexpected classes or wrappers
223
+
224
+ Check `MenuBar.config` overrides and project CSS specificity.
225
+
226
+ ### Empty separators at the end
227
+
228
+ `remove_dangling_separators` defaults to `true` and removes trailing separators.
229
+
230
+ ## Development
231
+
232
+ - This gem is a Rails engine.
233
+ - Main DSL entry point: `lib/menu_bar.rb`
234
+ - Config defaults: `lib/easy_menu_configuration.rb`
235
+ - Shared helper behavior: `lib/easy_menu_helpers.rb`
236
+
237
+ ## License
238
+
239
+ MIT. See `MIT-LICENSE`.
@@ -45,7 +45,12 @@ module EasyMenu
45
45
  :menu_content_element => :li,
46
46
  :menu_group_title_element => :div,
47
47
  :menu_group_element => :ul,
48
- :menu_item_element => :div
48
+ :menu_item_element => :div,
49
+
50
+ # Right-aligned insertion strategy:
51
+ # - :legacy_prepend preserves historical float-right behavior (default)
52
+ # - :preserve_definition_order keeps right-aligned items in declaration order
53
+ :right_aligned_insert_strategy => :legacy_prepend
49
54
  }
50
55
 
51
56
  Bootstrap = {
data/lib/menu_bar.rb CHANGED
@@ -143,14 +143,27 @@ class MenuBar
143
143
  def store_menu_bar_content(mbc, options = {})
144
144
  if options[:index]
145
145
  @content.insert(options[:index], mbc)
146
- # Ensure that right aligned menu bar content appears on the page in the order it is inserted
147
146
  elsif mbc.right_aligned?
148
- @content.prepend(mbc)
147
+ if right_aligned_insert_strategy == :preserve_definition_order
148
+ @content << mbc
149
+ else
150
+ # Ensure that right aligned menu bar content appears on the page in the order it is inserted
151
+ # when rendered with float-based right alignment (legacy behavior).
152
+ @content.prepend(mbc)
153
+ end
149
154
  else
150
155
  @content << mbc
151
156
  end
152
157
  end
153
158
 
159
+ def right_aligned_insert_strategy
160
+ strategy = @options[:right_aligned_insert_strategy] || config[:right_aligned_insert_strategy]
161
+ strategy = strategy.to_sym if strategy.respond_to?(:to_sym)
162
+ return strategy if [:legacy_prepend, :preserve_definition_order].include?(strategy)
163
+
164
+ raise ArgumentError, "Unknown right_aligned_insert_strategy: #{strategy.inspect}"
165
+ end
166
+
154
167
  # ABSTRACT CLASSES
155
168
 
156
169
  class AbstractContent
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_menu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Jakobsen
8
8
  - Ryan Wallace
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2026-02-05 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
@@ -25,8 +24,6 @@ dependencies:
25
24
  - - ">="
26
25
  - !ruby/object:Gem::Version
27
26
  version: '3.1'
28
- description:
29
- email:
30
27
  executables: []
31
28
  extensions: []
32
29
  extra_rdoc_files: []
@@ -44,10 +41,8 @@ files:
44
41
  - lib/easy_menu_configuration.rb
45
42
  - lib/easy_menu_helpers.rb
46
43
  - lib/menu_bar.rb
47
- homepage:
48
44
  licenses: []
49
45
  metadata: {}
50
- post_install_message:
51
46
  rdoc_options: []
52
47
  require_paths:
53
48
  - lib
@@ -62,8 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
57
  - !ruby/object:Gem::Version
63
58
  version: '0'
64
59
  requirements: []
65
- rubygems_version: 3.4.1
66
- signing_key:
60
+ rubygems_version: 3.6.9
67
61
  specification_version: 4
68
62
  summary: Simple menu bar DSL for Rails views
69
63
  test_files: []