primer_view_components 0.0.15 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +78 -0
  3. data/app/components/primer/avatar_component.rb +24 -6
  4. data/app/components/primer/avatar_stack_component.html.erb +10 -0
  5. data/app/components/primer/avatar_stack_component.rb +81 -0
  6. data/app/components/primer/base_component.rb +8 -4
  7. data/app/components/primer/blankslate_component.html.erb +4 -4
  8. data/app/components/primer/blankslate_component.rb +34 -8
  9. data/app/components/primer/border_box_component.rb +29 -13
  10. data/app/components/primer/box_component.rb +10 -0
  11. data/app/components/primer/breadcrumb_component.rb +3 -2
  12. data/app/components/primer/button_component.rb +3 -3
  13. data/app/components/primer/button_group_component.html.erb +5 -0
  14. data/app/components/primer/button_group_component.rb +37 -0
  15. data/app/components/primer/button_marketing_component.rb +73 -0
  16. data/app/components/primer/component.rb +13 -0
  17. data/app/components/primer/counter_component.rb +16 -9
  18. data/app/components/primer/details_component.rb +10 -6
  19. data/app/components/primer/dropdown/menu_component.html.erb +12 -0
  20. data/app/components/primer/dropdown/menu_component.rb +48 -0
  21. data/app/components/primer/dropdown_component.html.erb +9 -0
  22. data/app/components/primer/dropdown_component.rb +77 -0
  23. data/app/components/primer/dropdown_menu_component.rb +35 -3
  24. data/app/components/primer/flash_component.rb +10 -7
  25. data/app/components/primer/flex_component.rb +47 -9
  26. data/app/components/primer/flex_item_component.rb +16 -1
  27. data/app/components/primer/heading_component.rb +7 -0
  28. data/app/components/primer/label_component.rb +6 -6
  29. data/app/components/primer/layout_component.rb +2 -2
  30. data/app/components/primer/link_component.rb +7 -3
  31. data/app/components/primer/markdown_component.rb +293 -0
  32. data/app/components/primer/menu_component.html.erb +6 -0
  33. data/app/components/primer/menu_component.rb +71 -0
  34. data/app/components/primer/octicon_component.rb +11 -6
  35. data/app/components/primer/popover_component.rb +6 -4
  36. data/app/components/primer/progress_bar_component.rb +9 -9
  37. data/app/components/primer/slot.rb +1 -0
  38. data/app/components/primer/spinner_component.rb +10 -7
  39. data/app/components/primer/state_component.rb +6 -6
  40. data/app/components/primer/subhead_component.rb +6 -3
  41. data/app/components/primer/text_component.rb +1 -1
  42. data/app/components/primer/timeline_item_component.rb +4 -1
  43. data/app/components/primer/tooltip_component.rb +88 -0
  44. data/app/components/primer/truncate_component.rb +41 -0
  45. data/app/components/primer/underline_nav_component.rb +26 -1
  46. data/app/components/primer/view_components.rb +9 -0
  47. data/lib/primer/class_name_helper.rb +1 -0
  48. data/lib/primer/classify.rb +139 -107
  49. data/lib/primer/classify/cache.rb +125 -0
  50. data/lib/primer/fetch_or_fallback_helper.rb +9 -0
  51. data/lib/primer/join_style_arguments_helper.rb +14 -0
  52. data/lib/primer/view_components.rb +32 -0
  53. data/lib/primer/view_components/engine.rb +1 -0
  54. data/lib/primer/view_components/version.rb +1 -1
  55. data/lib/yard/renders_many_handler.rb +19 -0
  56. data/lib/yard/renders_one_handler.rb +19 -0
  57. data/static/statuses.json +1 -0
  58. metadata +80 -19
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ class Classify
5
+ # :nodoc:
6
+ class Cache
7
+ # rubocop:disable Style/MutableConstant
8
+ LOOKUP = {}
9
+ # rubocop:enable Style/MutableConstant
10
+
11
+ class <<self
12
+ def read(memo, key, val, breakpoint)
13
+ value = LOOKUP.dig(breakpoint, key, val)
14
+ memo[:classes] << value if value
15
+ end
16
+
17
+ def clear!
18
+ LOOKUP.clear
19
+ end
20
+
21
+ def preload!
22
+ preload(
23
+ keys: Primer::Classify::MARGIN_DIRECTION_KEYS,
24
+ values: [-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6]
25
+ )
26
+
27
+ preload(
28
+ keys: (Primer::Classify::SPACING_KEYS - Primer::Classify::MARGIN_DIRECTION_KEYS),
29
+ values: [0, 1, 2, 3, 4, 5, 6]
30
+ )
31
+
32
+ preload(
33
+ keys: Primer::Classify::DIRECTION_KEY,
34
+ values: [:row, :column]
35
+ )
36
+
37
+ preload(
38
+ keys: Primer::Classify::JUSTIFY_CONTENT_KEY,
39
+ values: [:flex_start, :flex_end, :center, :space_between, :space_around]
40
+ )
41
+
42
+ preload(
43
+ keys: Primer::Classify::ALIGN_ITEMS_KEY,
44
+ values: [:flex_start, :flex_end, :center, :baseline, :stretch]
45
+ )
46
+
47
+ preload(
48
+ keys: Primer::Classify::DISPLAY_KEY,
49
+ values: [:flex, :block, :inline_block, :inline_flex, :none, :table, :table_cell]
50
+ )
51
+
52
+ preload(
53
+ keys: [Primer::Classify::COLOR_KEY, Primer::Classify::BG_KEY],
54
+ values: [:blue, :gray_dark, :gray, :gray_light, :red, :orange, :orange_light, :yellow, :green, :purple, :white, :pink]
55
+ )
56
+
57
+ preload(
58
+ keys: Primer::Classify::VERTICAL_ALIGN_KEY,
59
+ values: [:baseline, :top, :middle, :bottom, :text_top, :text_bottom]
60
+ )
61
+
62
+ preload(
63
+ keys: Primer::Classify::WORD_BREAK_KEY,
64
+ values: [:break_all]
65
+ )
66
+
67
+ preload(
68
+ keys: :text_align,
69
+ values: [:left, :center, :right]
70
+ )
71
+
72
+ preload(
73
+ keys: :font_weight,
74
+ values: [:bold, :light, :normal]
75
+ )
76
+
77
+ preload(
78
+ keys: Primer::Classify::FLEX_KEY,
79
+ values: [1, :auto]
80
+ )
81
+
82
+ preload(
83
+ keys: [Primer::Classify::FLEX_GROW_KEY, Primer::Classify::FLEX_SHRINK_KEY],
84
+ values: [0]
85
+ )
86
+
87
+ preload(
88
+ keys: [Primer::Classify::ALIGN_SELF_KEY],
89
+ values: [:auto, :start, :end, :center, :baseline, :stretch]
90
+ )
91
+
92
+ preload(
93
+ keys: [Primer::Classify::WIDTH_KEY, Primer::Classify::HEIGHT_KEY],
94
+ values: [:fit, :fill]
95
+ )
96
+
97
+ preload(
98
+ keys: Primer::Classify::BOX_SHADOW_KEY,
99
+ values: [true, :medium, :large, :extra_large, :none]
100
+ )
101
+
102
+ preload(
103
+ keys: Primer::Classify::VISIBILITY_KEY,
104
+ values: [:hidden, :visible]
105
+ )
106
+ end
107
+
108
+ def preload(keys:, values:)
109
+ BREAKPOINTS.each do |breakpoint|
110
+ Array(keys).each do |key|
111
+ values.each do |value|
112
+ classes = { classes: [] }
113
+ Primer::Classify.send(:extract_value, classes, key, value, breakpoint)
114
+
115
+ LOOKUP[breakpoint] ||= {}
116
+ LOOKUP[breakpoint][key] ||= {}
117
+ LOOKUP[breakpoint][key][value] = classes[:classes].first
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -14,6 +14,7 @@
14
14
  # fetch_or_fallback([1,2,3], 1, 2) => 1
15
15
  # fetch_or_fallback([1,2,3], nil, 2) => 2
16
16
  module Primer
17
+ # :nodoc:
17
18
  module FetchOrFallbackHelper
18
19
  mattr_accessor :fallback_raises, default: true
19
20
 
@@ -37,5 +38,13 @@ module Primer
37
38
  fallback
38
39
  end
39
40
  end
41
+
42
+ def fetch_or_fallback_boolean(given_value, fallback = false)
43
+ if [true, false].include?(given_value)
44
+ given_value
45
+ else
46
+ fallback
47
+ end
48
+ end
40
49
  end
41
50
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ # :nodoc:
5
+ module JoinStyleArgumentsHelper
6
+ # Join two `style` arguments
7
+ #
8
+ # join_style_arguments("width: 100%", "height: 100%") =>
9
+ # "width: 100%;height: 100%"
10
+ def join_style_arguments(*args)
11
+ args.compact.join(";")
12
+ end
13
+ end
14
+ end
@@ -4,6 +4,38 @@ require "primer/view_components/version"
4
4
  require "primer/view_components/engine"
5
5
 
6
6
  module Primer
7
+ # :nodoc:
7
8
  module ViewComponents
9
+ DEFAULT_STATUSES_PATH = File.expand_path("static")
10
+ DEFAULT_STATUS_FILE_NAME = "statuses.json"
11
+
12
+ # generate_statuses returns a hash mapping component name to
13
+ # the component's status sorted alphabetically by the component name.
14
+ def self.generate_statuses
15
+ statuses = Primer::Component.descendants.each_with_object({}) do |component, mem|
16
+ mem[component.to_s] = component.status.to_s
17
+ end
18
+
19
+ statuses.sort_by { |k, _v| k }.to_h
20
+ end
21
+
22
+ # dump_statuses generates the status hash and then serializes
23
+ # it as json at the given path
24
+ def self.dump_statuses(path: DEFAULT_STATUSES_PATH)
25
+ require "json"
26
+
27
+ statuses = generate_statuses
28
+
29
+ File.open(File.join(path, DEFAULT_STATUS_FILE_NAME), "w") do |f|
30
+ f.write(statuses.to_json)
31
+ f.write($INPUT_RECORD_SEPARATOR)
32
+ end
33
+ end
34
+
35
+ # read_statuses returns a JSON string matching the output of
36
+ # generate_statuses
37
+ def self.read_statuses(path: DEFAULT_STATUSES_PATH)
38
+ File.read(File.join(path, DEFAULT_STATUS_FILE_NAME))
39
+ end
8
40
  end
9
41
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Primer
4
4
  module ViewComponents
5
+ # :nodoc:
5
6
  class Engine < ::Rails::Engine
6
7
  isolate_namespace Primer::ViewComponents
7
8
  end
@@ -5,7 +5,7 @@ module Primer
5
5
  module VERSION
6
6
  MAJOR = 0
7
7
  MINOR = 0
8
- PATCH = 15
8
+ PATCH = 20
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH].join(".")
11
11
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YARD
4
+ # YARD Handler to parse `renders_many` calls.
5
+ class RendersManyHandler < YARD::Handlers::Ruby::Base
6
+ handles method_call(:renders_many)
7
+ namespace_only
8
+
9
+ process do
10
+ name = statement.parameters.first.jump(:tstring_content, :ident).source
11
+ object = YARD::CodeObjects::MethodObject.new(namespace, name)
12
+ register(object)
13
+ parse_block(statement.last, owner: object)
14
+
15
+ object.dynamic = true
16
+ object[:renders_many] = true
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YARD
4
+ # YARD Handler to parse `renders_one` calls.
5
+ class RendersOneHandler < YARD::Handlers::Ruby::Base
6
+ handles method_call(:renders_one)
7
+ namespace_only
8
+
9
+ process do
10
+ name = statement.parameters.first.jump(:tstring_content, :ident).source
11
+ object = YARD::CodeObjects::MethodObject.new(namespace, name)
12
+ register(object)
13
+ parse_block(statement.last, owner: object)
14
+
15
+ object.dynamic = true
16
+ object[:renders_one] = true
17
+ end
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ {"Primer::AvatarComponent":"beta","Primer::AvatarStackComponent":"alpha","Primer::BaseComponent":"alpha","Primer::BlankslateComponent":"alpha","Primer::BorderBoxComponent":"beta","Primer::BoxComponent":"stable","Primer::BreadcrumbComponent":"alpha","Primer::ButtonComponent":"alpha","Primer::ButtonGroupComponent":"alpha","Primer::ButtonMarketingComponent":"alpha","Primer::CounterComponent":"beta","Primer::DetailsComponent":"alpha","Primer::Dropdown::MenuComponent":"alpha","Primer::DropdownComponent":"alpha","Primer::DropdownMenuComponent":"deprecated","Primer::FlashComponent":"beta","Primer::FlexComponent":"alpha","Primer::FlexItemComponent":"alpha","Primer::HeadingComponent":"alpha","Primer::LabelComponent":"alpha","Primer::LayoutComponent":"alpha","Primer::LinkComponent":"beta","Primer::MarkdownComponent":"alpha","Primer::MenuComponent":"alpha","Primer::OcticonComponent":"beta","Primer::PopoverComponent":"alpha","Primer::ProgressBarComponent":"alpha","Primer::SpinnerComponent":"beta","Primer::StateComponent":"alpha","Primer::SubheadComponent":"alpha","Primer::TextComponent":"alpha","Primer::TimelineItemComponent":"alpha","Primer::TooltipComponent":"alpha","Primer::TruncateComponent":"alpha","Primer::UnderlineNavComponent":"alpha"}
metadata CHANGED
@@ -1,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: primer_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-20 00:00:00.000000000 Z
11
+ date: 2021-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octicons_helper
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 9.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 13.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 9.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 13.0.0
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: rails
15
35
  requirement: !ruby/object:Gem::Requirement
@@ -51,25 +71,33 @@ dependencies:
51
71
  - !ruby/object:Gem::Version
52
72
  version: '3.0'
53
73
  - !ruby/object:Gem::Dependency
54
- name: octicons_helper
74
+ name: allocation_tracer
55
75
  requirement: !ruby/object:Gem::Requirement
56
76
  requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- version: 9.0.0
60
- - - "<"
77
+ - - "~>"
61
78
  - !ruby/object:Gem::Version
62
- version: 12.0.0
63
- type: :runtime
79
+ version: 0.6.3
80
+ type: :development
64
81
  prerelease: false
65
82
  version_requirements: !ruby/object:Gem::Requirement
66
83
  requirements:
67
- - - ">="
84
+ - - "~>"
68
85
  - !ruby/object:Gem::Version
69
- version: 9.0.0
70
- - - "<"
86
+ version: 0.6.3
87
+ - !ruby/object:Gem::Dependency
88
+ name: benchmark-ips
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
71
92
  - !ruby/object:Gem::Version
72
- version: 12.0.0
93
+ version: 2.8.4
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: 2.8.4
73
101
  - !ruby/object:Gem::Dependency
74
102
  name: listen
75
103
  requirement: !ruby/object:Gem::Requirement
@@ -118,28 +146,42 @@ dependencies:
118
146
  requirements:
119
147
  - - '='
120
148
  - !ruby/object:Gem::Version
121
- version: '0.74'
149
+ version: '0.82'
122
150
  type: :development
123
151
  prerelease: false
124
152
  version_requirements: !ruby/object:Gem::Requirement
125
153
  requirements:
126
154
  - - '='
127
155
  - !ruby/object:Gem::Version
128
- version: '0.74'
156
+ version: '0.82'
129
157
  - !ruby/object:Gem::Dependency
130
158
  name: rubocop-github
131
159
  requirement: !ruby/object:Gem::Requirement
132
160
  requirements:
133
161
  - - "~>"
134
162
  - !ruby/object:Gem::Version
135
- version: 0.13.0
163
+ version: 0.16.0
164
+ type: :development
165
+ prerelease: false
166
+ version_requirements: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - "~>"
169
+ - !ruby/object:Gem::Version
170
+ version: 0.16.0
171
+ - !ruby/object:Gem::Dependency
172
+ name: rubocop-performance
173
+ requirement: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - "~>"
176
+ - !ruby/object:Gem::Version
177
+ version: '1.7'
136
178
  type: :development
137
179
  prerelease: false
138
180
  version_requirements: !ruby/object:Gem::Requirement
139
181
  requirements:
140
182
  - - "~>"
141
183
  - !ruby/object:Gem::Version
142
- version: 0.13.0
184
+ version: '1.7'
143
185
  - !ruby/object:Gem::Dependency
144
186
  name: simplecov
145
187
  requirement: !ruby/object:Gem::Requirement
@@ -193,6 +235,8 @@ files:
193
235
  - LICENSE.txt
194
236
  - README.md
195
237
  - app/components/primer/avatar_component.rb
238
+ - app/components/primer/avatar_stack_component.html.erb
239
+ - app/components/primer/avatar_stack_component.rb
196
240
  - app/components/primer/base_component.rb
197
241
  - app/components/primer/blankslate_component.html.erb
198
242
  - app/components/primer/blankslate_component.rb
@@ -202,10 +246,17 @@ files:
202
246
  - app/components/primer/breadcrumb_component.html.erb
203
247
  - app/components/primer/breadcrumb_component.rb
204
248
  - app/components/primer/button_component.rb
249
+ - app/components/primer/button_group_component.html.erb
250
+ - app/components/primer/button_group_component.rb
251
+ - app/components/primer/button_marketing_component.rb
205
252
  - app/components/primer/component.rb
206
253
  - app/components/primer/counter_component.rb
207
254
  - app/components/primer/details_component.html.erb
208
255
  - app/components/primer/details_component.rb
256
+ - app/components/primer/dropdown/menu_component.html.erb
257
+ - app/components/primer/dropdown/menu_component.rb
258
+ - app/components/primer/dropdown_component.html.erb
259
+ - app/components/primer/dropdown_component.rb
209
260
  - app/components/primer/dropdown_menu_component.html.erb
210
261
  - app/components/primer/dropdown_menu_component.rb
211
262
  - app/components/primer/flash_component.html.erb
@@ -217,6 +268,9 @@ files:
217
268
  - app/components/primer/layout_component.html.erb
218
269
  - app/components/primer/layout_component.rb
219
270
  - app/components/primer/link_component.rb
271
+ - app/components/primer/markdown_component.rb
272
+ - app/components/primer/menu_component.html.erb
273
+ - app/components/primer/menu_component.rb
220
274
  - app/components/primer/octicon_component.rb
221
275
  - app/components/primer/popover_component.html.erb
222
276
  - app/components/primer/popover_component.rb
@@ -231,15 +285,22 @@ files:
231
285
  - app/components/primer/text_component.rb
232
286
  - app/components/primer/timeline_item_component.html.erb
233
287
  - app/components/primer/timeline_item_component.rb
288
+ - app/components/primer/tooltip_component.rb
289
+ - app/components/primer/truncate_component.rb
234
290
  - app/components/primer/underline_nav_component.html.erb
235
291
  - app/components/primer/underline_nav_component.rb
236
292
  - app/components/primer/view_components.rb
237
293
  - lib/primer/class_name_helper.rb
238
294
  - lib/primer/classify.rb
295
+ - lib/primer/classify/cache.rb
239
296
  - lib/primer/fetch_or_fallback_helper.rb
297
+ - lib/primer/join_style_arguments_helper.rb
240
298
  - lib/primer/view_components.rb
241
299
  - lib/primer/view_components/engine.rb
242
300
  - lib/primer/view_components/version.rb
301
+ - lib/yard/renders_many_handler.rb
302
+ - lib/yard/renders_one_handler.rb
303
+ - static/statuses.json
243
304
  homepage: https://github.com/primer/view_components
244
305
  licenses:
245
306
  - MIT
@@ -253,14 +314,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
253
314
  requirements:
254
315
  - - ">="
255
316
  - !ruby/object:Gem::Version
256
- version: 2.3.0
317
+ version: 2.5.0
257
318
  required_rubygems_version: !ruby/object:Gem::Requirement
258
319
  requirements:
259
320
  - - ">="
260
321
  - !ruby/object:Gem::Version
261
322
  version: '0'
262
323
  requirements: []
263
- rubygems_version: 3.1.2
324
+ rubygems_version: 3.0.3
264
325
  signing_key:
265
326
  specification_version: 4
266
327
  summary: ViewComponents for the Primer Design System