russian_hill 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: 4f25cf524bb175d4bb2454a35ff6ec07848d0a9632cb18a5444b7c8119df21e8
4
+ data.tar.gz: c94cdbbafb6a46ba1bc98a27b210656c4cdbcf4f39764433f6bdd0bcef3f8c08
5
+ SHA512:
6
+ metadata.gz: 7840c9b7a7bd400a18773a9c96a6e688c99d73c6501d52231a1a9de9f8acd5f6763270a6d91238bed9d4cd7437df7c9f88418b0f848b9196f9573fd1c3eab9f3
7
+ data.tar.gz: 71c9c948e59bf6652c93d2d248e736d69c1c54056035b59adcfd11f34eba4adfcd4cbe253c58fcd7e2b8358fa42e055edc834ad6a0fc870ed24be7487d3f360d
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2021 Rafe Rosen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # RussianHill
2
+ Jbuilder-like views for CableReady's cable_car. Registers a .cablecar template extension and cablecar MIME type for a dedicated view you can use to build up operations to send in a response by calling e.g. `operations.morph`
3
+
4
+ ![picture of SF cable car](russianhill.jpg)
5
+
6
+
7
+ ## Usage
8
+ Example code:
9
+
10
+ app/controllers/demos_controller.rb
11
+ ```ruby
12
+ class DemosController < ApplicationController
13
+
14
+ def index
15
+ respond_to do |format|
16
+ format.html
17
+ format.cablecar { @message = "Hello World!"}
18
+ end
19
+ end
20
+
21
+ end
22
+ ```
23
+
24
+ app/views/demos/index.cablecar
25
+ ```
26
+ operations.morph(selector: "#message", html: @message)
27
+
28
+ operations.inner_html(selector: "#inner", html: "Hi inner!")
29
+
30
+ operations.outer_html(selector: "#outer", html: render(partial: "message", formats: :html))
31
+
32
+ ```
33
+
34
+
35
+ app/views/demos/index.html.erb
36
+ ```html
37
+ <div id="message"></div>
38
+
39
+ <div id="inner"></div>
40
+
41
+ <div id="outer"></div>
42
+
43
+ <script>
44
+ window
45
+ .mrujs
46
+ .fetch("/cable_car_views", {headers: {"Accept": "text/vnd.cablecar.json"}})
47
+ .then(response => response.json()
48
+ .then(j => {
49
+ console.log(j)
50
+ CableReady.perform(j)
51
+ })
52
+ )
53
+ </script>
54
+
55
+ ```
56
+
57
+ app/views/demos/_message.html.erb
58
+ ```html
59
+ Hello Partial!
60
+
61
+ <p>Here's some html</p>
62
+
63
+ <b><%= @message %></b>
64
+
65
+ ```
66
+
67
+ ## Installation
68
+ Add this line to your application's Gemfile:
69
+
70
+ ```ruby
71
+ gem 'russian_hill'
72
+ ```
73
+
74
+ And then execute:
75
+ ```bash
76
+ $ bundle
77
+ ```
78
+
79
+ Or install it yourself as:
80
+ ```bash
81
+ $ gem install russian_hill
82
+ ```
83
+
84
+ ## Contributing
85
+ Contribution directions go here.
86
+
87
+ ## License
88
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ require "rake/testtask"
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = false
11
+ end
12
+
13
+ task default: :test
@@ -0,0 +1,37 @@
1
+ require "russian_hill/version"
2
+
3
+ class RussianHill
4
+ include CableReady::Broadcaster
5
+
6
+ def initialize(context)
7
+ @context = context
8
+ @operations = cable_car
9
+ yield self if ::Kernel.block_given?
10
+ end
11
+
12
+ # Yields a builder and automatically turns the result into a JSON string
13
+ def self.encode(*args, &block)
14
+ new(*args, &block).target!
15
+ end
16
+
17
+ def target!
18
+ @operations.dispatch.to_json
19
+ end
20
+
21
+ def method_missing symbol, *args
22
+ @operations = @operations.public_send(symbol, *args)
23
+ end
24
+ end
25
+
26
+ class CableCarHandler
27
+ cattr_accessor :default_format
28
+ self.default_format = :cablecar
29
+
30
+ def self.call(template, source = nil)
31
+ source ||= template.source
32
+ # this juggling is required to keep line numbers right in the error
33
+ %{__already_defined = defined?(operations); operations||=RussianHill.new(self); #{source}
34
+ operations.target! unless (__already_defined && __already_defined != "method")}
35
+ end
36
+ end
37
+ require 'russian_hill/railtie' if defined?(Rails)
@@ -0,0 +1,61 @@
1
+ require 'russian_hill/russian_hill'
2
+
3
+ dependency_tracker = false
4
+
5
+ begin
6
+ require 'action_view'
7
+ require 'action_view/dependency_tracker'
8
+ dependency_tracker = ::ActionView::DependencyTracker
9
+ rescue LoadError
10
+ begin
11
+ require 'cache_digests'
12
+ dependency_tracker = ::CacheDigests::DependencyTracker
13
+ rescue LoadError
14
+ end
15
+ end
16
+
17
+ if dependency_tracker
18
+ class RussianHill
19
+ module DependencyTrackerMethods
20
+ # Matches:
21
+ # json.partial! "messages/message"
22
+ # json.partial!('messages/message')
23
+ #
24
+ DIRECT_RENDERS = /
25
+ \w+\.partial! # json.partial!
26
+ \(?\s* # optional parenthesis
27
+ (['"])([^'"]+)\1 # quoted value
28
+ /x
29
+
30
+ # Matches:
31
+ # json.partial! partial: "comments/comment"
32
+ # json.comments @post.comments, partial: "comments/comment", as: :comment
33
+ # json.array! @posts, partial: "posts/post", as: :post
34
+ # = render partial: "account"
35
+ #
36
+ INDIRECT_RENDERS = /
37
+ (?::partial\s*=>|partial:) # partial: or :partial =>
38
+ \s* # optional whitespace
39
+ (['"])([^'"]+)\1 # quoted value
40
+ /x
41
+
42
+ def dependencies
43
+ direct_dependencies + indirect_dependencies + explicit_dependencies
44
+ end
45
+
46
+ private
47
+
48
+ def direct_dependencies
49
+ source.scan(DIRECT_RENDERS).map(&:second)
50
+ end
51
+
52
+ def indirect_dependencies
53
+ source.scan(INDIRECT_RENDERS).map(&:second)
54
+ end
55
+ end
56
+ end
57
+
58
+ ::RussianHill::DependencyTracker = Class.new(dependency_tracker::ERBTracker)
59
+ ::RussianHill::DependencyTracker.send :include, ::RussianHill::DependencyTrackerMethods
60
+ dependency_tracker.register_tracker :jbuilder, ::RussianHill::DependencyTracker
61
+ end
@@ -0,0 +1,11 @@
1
+ class RussianHill
2
+ class Railtie < ::Rails::Railtie
3
+ initializer :cablecar do
4
+ ActiveSupport.on_load :action_view do
5
+ ActionView::Template.register_template_handler :cablecar, CableCarHandler
6
+ end
7
+
8
+ Mime::Type.register "text/vnd.cablecar.json", :cablecar
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ RussianHill = Class.new(begin
2
+ require 'active_support/proxy_object'
3
+ ActiveSupport::ProxyObject
4
+ rescue LoadError
5
+ require 'active_support/basic_object'
6
+ ActiveSupport::BasicObject
7
+ end)
@@ -0,0 +1,3 @@
1
+ class RussianHill
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :russian_hill do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: russian_hill
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rafe Rosen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 6.1.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 6.1.4
27
+ description: Provides JBuilder-like views for building CableReady operations.
28
+ email:
29
+ - rafe@existentialmutt.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/russian_hill.rb
38
+ - lib/russian_hill/dependency_tracker.rb
39
+ - lib/russian_hill/railtie.rb
40
+ - lib/russian_hill/russian_hill.rb
41
+ - lib/russian_hill/version.rb
42
+ - lib/tasks/russian_hill_tasks.rake
43
+ homepage: http://github.com/existentialmutt/russian_hill
44
+ licenses:
45
+ - MIT
46
+ metadata:
47
+ homepage_uri: http://github.com/existentialmutt/russian_hill
48
+ source_code_uri: http://github.com/existentialmutt/russian_hill
49
+ changelog_uri: http://github.com/existentialmutt/russian_hill/releases
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.1.6
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: Views for CableReady's cable_car
69
+ test_files: []