grand_central-dev_tools 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d064f30d62199d135226b937cef4b0787b505e78923ce4f599cd0666eb2f2c21
4
+ data.tar.gz: d093c0b24c760641a110a8470d6157a2b2b9f770e574d99da34b0afc039f1eb6
5
+ SHA512:
6
+ metadata.gz: 4e5a4f0125d8d055377535b2d401093f1cb6cbbc5d32e0bdfde24ef41ee70077351d110d155ecbe31404d0204bcee198a6a32e3700719d5488b4fdc5568a57af
7
+ data.tar.gz: 546eec823b0c2290f6b5bcbc8332c12d3bb3bcc804be02848329128c9b6975564727948ce9cf05e330b887d946f68ad023a1bec8a44092962c15cb4b8c2db2b9
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at jgaskins@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in grand_central-dev_tools.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Jamie Gaskins
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # GrandCentral::DevTools
2
+
3
+ Client-side developer tools for the [`grand_central` gem](https://github.com/clearwater-rb/grand_central).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'grand_central-dev_tools'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ Add a div to your HTML document for the dev tools to render into:
20
+
21
+ ```html
22
+ <div id="grand-central"></div>
23
+ ```
24
+
25
+ If you have a `dev.rb` or some other development-only asset, you'll want to add it into there:
26
+
27
+ ```ruby
28
+ # dev.rb
29
+ require 'grand_central/dev_tools'
30
+ require 'store' # Change this to wherever your GrandCentral store is loaded from
31
+
32
+ dev_tools = GrandCentral::DevTools.new(
33
+ Store, # Your store object goes here. Any store type will work.
34
+ Bowser.document['#grand-central'] # The div we added to our HTML document.
35
+ )
36
+ dev_tools.start # Actually begin monitoring the store
37
+ ```
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/clearwater-rb/grand_central-dev_tools. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
48
+
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
53
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "grand_central/dev_tools"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'grand_central/dev_tools/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "grand_central-dev_tools"
8
+ spec.version = GrandCentral::DevTools::VERSION
9
+ spec.authors = ["Jamie Gaskins"]
10
+ spec.email = ["jgaskins@gmail.com"]
11
+
12
+ spec.summary = %q{Client-side developer tools for GrandCentral}
13
+ spec.homepage = "https://github.com/clearwater-rb/grand_central-dev_tools"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.14"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
@@ -0,0 +1,5 @@
1
+ module GrandCentral
2
+ module DevTools
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'grand_central/dev_tools/version'
2
+ require 'clearwater'
3
+ require 'grand_central'
4
+
5
+ Opal.append_path File.expand_path('../../../opal', __FILE__)
@@ -0,0 +1,316 @@
1
+ require 'clearwater'
2
+ require 'clearwater/black_box_node'
3
+
4
+ module GrandCentral
5
+ class DevTools
6
+ include Clearwater::Component
7
+
8
+ def initialize store, element
9
+ @store = store
10
+ @app = Clearwater::Application.new(
11
+ component: self,
12
+ element: element,
13
+ )
14
+ @initial_state = store.state
15
+ @dispatches = []
16
+ end
17
+
18
+ def start
19
+ @app.render
20
+ @store.on_dispatch do |old, new, action|
21
+ @dispatches += [Dispatch.new(old, new, action)]
22
+ @app.render
23
+ end
24
+ end
25
+
26
+ def render
27
+ div({
28
+ style: {
29
+ font_family: 'monospace',
30
+ position: :fixed,
31
+ background: '#555',
32
+ color: :white,
33
+ top: 0,
34
+ right: 0,
35
+ padding: '1em',
36
+ box_shadow: '0 0 5px black',
37
+ overflow: :scroll,
38
+ box_sizing: 'border-box',
39
+ max_height: '100vh',
40
+ },
41
+ }, [
42
+ if @open
43
+ div([
44
+ div({ style: { text_align: :right } }, [
45
+ button({ onclick: proc { @open = false; @app.render } }, '-'),
46
+ ]),
47
+ h2('State'),
48
+ ModelPresenter.memoize(@store.state),
49
+ h2('Actions'),
50
+ div(@dispatches.map { |dispatch|
51
+ DispatchPresenter.memoize(
52
+ dispatch,
53
+ oncommit: proc {
54
+ `#@store.state = #{dispatch.after}`
55
+ index = @dispatches.index dispatch
56
+ @dispatches = @dispatches[0..index]
57
+ call
58
+ @app.render
59
+ },
60
+ ondelete: proc {
61
+ @dispatches = @dispatches.reject { |d| d == dispatch }
62
+ new_dispatches = []
63
+ new_state = @dispatches.reduce(@initial_state) do |state, d|
64
+ s = `#@store.reducer`.call state, d.action
65
+ new_dispatches << Dispatch.new(state, s, d.action)
66
+ s
67
+ end
68
+ @dispatches = new_dispatches
69
+ `#@store.state = #{new_state}`
70
+ call
71
+ @app.render
72
+ }
73
+ )[dispatch.object_id]
74
+ }),
75
+ ])
76
+ else
77
+ div({ style: { text_align: :right } }, [
78
+ span('Grand Central Dev Tools'),
79
+ button({ onclick: proc { @open = true; @app.render } }, '+'),
80
+ ])
81
+ end,
82
+ ])
83
+ end
84
+
85
+ # Dispatch = Struct.new(:before_state, :after_state, :action)
86
+ class Dispatch
87
+ attr_reader :before, :after, :action
88
+
89
+ def initialize before, after, action
90
+ @before = before
91
+ @action = action
92
+ @after = after
93
+ end
94
+
95
+ def == other
96
+ return false unless other.class == self.class
97
+
98
+ action == other.action
99
+ end
100
+ end
101
+
102
+ class Presenter
103
+ include Clearwater::Component
104
+
105
+ attr_reader :model
106
+ attr_accessor :placeholder
107
+
108
+ def self.memoize *args, &block
109
+ Placeholder.new(self, args, block)
110
+ end
111
+
112
+ def initialize model
113
+ @model = model
114
+ end
115
+
116
+ def update model
117
+ @model = model
118
+ end
119
+
120
+ def should_update? model
121
+ !model.equal? @model
122
+ end
123
+
124
+ def update_self *args
125
+ args = [@model] if args.empty?
126
+
127
+ self.class.memoize(*args).update_self @placeholder, true
128
+ end
129
+
130
+ def serialize_value value
131
+ case value
132
+ when String, Numeric, true, false, nil
133
+ code(value.inspect)
134
+ when Array
135
+ ArrayPresenter.memoize value
136
+ when Hash
137
+ HashPresenter.memoize value
138
+ when Set
139
+ SetPresenter.memoize value
140
+ else
141
+ ModelPresenter.memoize value
142
+ end
143
+ end
144
+
145
+ def set ivar, value
146
+ proc do
147
+ `self[ivar] = value`
148
+ update_self model
149
+ end
150
+ end
151
+
152
+ class Placeholder
153
+ include Clearwater::BlackBoxNode
154
+
155
+ attr_reader :klass, :key, :element, :node, :vdom
156
+
157
+ def initialize klass, args, block
158
+ @klass = klass
159
+ @args = args
160
+ @block = block
161
+ end
162
+
163
+ def [] key
164
+ @key = key.to_s
165
+ self
166
+ end
167
+
168
+ def component
169
+ @component ||= @klass.new(*@args, &@block)
170
+ end
171
+
172
+ def node
173
+ @node ||= Clearwater::Component.sanitize_content(component)
174
+ end
175
+
176
+ def mount element
177
+ @vdom = Clearwater::VirtualDOM::Document.new(element)
178
+ `#@vdom.tree = #{element.to_n}`
179
+ `#@vdom.node = #{node}`
180
+ `#@vdom.rendered = true`
181
+ @component.placeholder = self
182
+ end
183
+
184
+ def update previous
185
+ update_self previous
186
+ end
187
+
188
+ def update_self previous, override=false
189
+ @vdom = previous.vdom
190
+ @component = previous.component
191
+
192
+ if override || component.should_update?(*@args, &@block)
193
+ component.update(*@args, &@block)
194
+ @component.placeholder = self
195
+ @vdom.render component.render
196
+ end
197
+ end
198
+ end
199
+ end
200
+
201
+ class ModelPresenter < Presenter
202
+ def render
203
+ attributes = model
204
+ .instance_variables
205
+ .map { |ivar| ivar.sub(/^@/, '') }
206
+ .sort
207
+ .map { |attr| [attr, `#{model}[#{attr}]`] }
208
+
209
+ div({ style: { display: 'inline-block' } }, [
210
+ h3({ style: { margin: 0 } }, model.class.name),
211
+ table([
212
+ tbody(attributes.map { |attr, value|
213
+ tr({ key: attr, style: { vertical_align: :top } }, [
214
+ th({ style: { text_align: :right, margin_right: '1em' } }, attr),
215
+ td(serialize_value value),
216
+ ])
217
+ }),
218
+ ]),
219
+ ])
220
+ end
221
+ end
222
+
223
+ class ArrayPresenter < Presenter
224
+ alias array model
225
+
226
+ def render
227
+ div({ style: { display: 'inline-block' } }, [
228
+ '[',
229
+ button({ onclick: set(:show_contents, !@show_contents) }, @show_contents ? '-' : "#{array.count} items"),
230
+ if @show_contents
231
+ div({ style: { padding_left: '1em' } }, [
232
+ array.map { |item| div(serialize_value(item)) },
233
+ ])
234
+ end,
235
+ ']',
236
+ ])
237
+ end
238
+ end
239
+
240
+ class HashPresenter < Presenter
241
+ alias hash model
242
+
243
+ def render
244
+ div([
245
+ '{',
246
+ hash.any? ? button({ onclick: set(:show_contents, !@show_contents) }, @show_contents ? '-' : "#{hash.count} key#{'s' unless hash.one?}") : nil,
247
+ if @show_contents
248
+ div({ style: { padding_left: '2em' } }, hash.map { |k, v|
249
+ div([
250
+ div({ style: { display: 'inline-block', vertical_align: :top } }, serialize_value(k)),
251
+ ' => ',
252
+ div({ style: { display: 'inline-block', vertical_align: :top } }, serialize_value(v)),
253
+ ])
254
+ })
255
+ end,
256
+ '}',
257
+ ])
258
+ end
259
+ end
260
+
261
+ class SetPresenter < Presenter
262
+ def render
263
+ div({ style: { display: 'inline-block' } }, [
264
+ 'Set[',
265
+ button({ onclick: set(:show_contents, !@show_contents) }, @show_contents ? '-' : "#{model.count} items"),
266
+ if @show_contents
267
+ div({ style: { padding_left: '1em' } }, [
268
+ model.map { |item| div(serialize_value(item)) },
269
+ ])
270
+ end,
271
+ ']',
272
+ ])
273
+ end
274
+ end
275
+
276
+ class DispatchPresenter < Presenter
277
+ def initialize dispatch, oncommit: proc {}, ondelete: proc {}
278
+ super dispatch
279
+ @oncommit = oncommit
280
+ @ondelete = ondelete
281
+ end
282
+
283
+ def update *args
284
+ initialize *args
285
+ end
286
+
287
+ def render
288
+ div([
289
+ div([
290
+ button({ onclick: set(:show_contents, !@show_contents) }, @show_contents ? '-' : '+'),
291
+ button({ onclick: @oncommit }, '!'),
292
+ button({ onclick: @ondelete }, 'x'),
293
+ model.action.class.name,
294
+ ]),
295
+ if @show_contents
296
+ dl({ style: { margin: 0 } }, [
297
+ dt('Action'),
298
+ dd(ModelPresenter.memoize(model.action)),
299
+ dt('Before'),
300
+ dd(ModelPresenter.memoize(model.before)),
301
+ dt('After'),
302
+ dd(ModelPresenter.memoize(model.after)),
303
+ ])
304
+ end,
305
+ ])
306
+ end
307
+
308
+ def set ivar, value
309
+ proc do
310
+ `self[ivar] = value`
311
+ update_self model, oncommit: @oncommit, ondelete: @ondelete
312
+ end
313
+ end
314
+ end
315
+ end
316
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grand_central-dev_tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jamie Gaskins
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - jgaskins@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - grand_central-dev_tools.gemspec
73
+ - lib/grand_central/dev_tools.rb
74
+ - lib/grand_central/dev_tools/version.rb
75
+ - opal/grand_central/dev_tools.rb
76
+ homepage: https://github.com/clearwater-rb/grand_central-dev_tools
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.7.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Client-side developer tools for GrandCentral
100
+ test_files: []