haken 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f8d40e52bacc9753ca563572a44eaeb96689de024dbc02d2dbca0583819a4405
4
+ data.tar.gz: 80b503d505ee57bab86e9ec46b1a80323ecb5ebdb59399a73ba2cb931127f1a5
5
+ SHA512:
6
+ metadata.gz: d0809f760acb7e21a19292a5f7c0e122bacfda17a1f9a5689161376ae1d0f86add74174846dfcec9f911d63b6db5956c59a1dfb0142b3e13739a5c1297907868
7
+ data.tar.gz: f1193638052ac7bcb59b4673cfbdb147201f5c11dc74ece7ed914031b6a9482f597a89f413590690cc6c374b8bd548cc28c88f612f9ec17ce7d454cb2dc55c0c
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in haken.gemspec
4
+ gemspec
5
+
6
+ gem 'rake', '~> 12.0'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Davis Namsons
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,25 @@
1
+ # Haken
2
+
3
+ A very simple gem for defining places where additional content can be injected from elsewhere.
4
+
5
+ ## Usage
6
+
7
+ Define a place where additional content can be injected:
8
+
9
+ `views/layouts/_navbar.html.erb`
10
+ ```erb
11
+ <nav>
12
+ <%= load_view_hooks_for :navbar %>
13
+ </nav>
14
+ ```
15
+
16
+ Then you can define a partial elsewhere(for example in a different Rails engine) and inject it into the navbar via an initializer like this:
17
+ ```rb
18
+ module MyEngine
19
+ class Engine < Rails::Engine
20
+ initializer 'my_engine.view_hooks' do
21
+ Haken.on_load(:navbar) { render 'layouts/my_engine/navbar_extension' }
22
+ end
23
+ end
24
+ end
25
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "haken"
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
data/haken.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ require_relative 'lib/haken/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'haken'
5
+ spec.version = Haken::VERSION
6
+ spec.authors = ['Davis Namsons']
7
+
8
+ spec.summary = 'Add load hooks into your views'
9
+ spec.description = 'Haken allows you to define places in your views where additional content can be injected from elsewhere(for example, a seperate rails engine)'
10
+ spec.license = 'MIT'
11
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
12
+
13
+ # Specify which files should be added to the gem when it is released.
14
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
15
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
16
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ end
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+ end
@@ -0,0 +1,9 @@
1
+ module Haken
2
+ module Helpers
3
+ def load_view_hooks_for(identifier, *args)
4
+ Listeners.load_hooks_for(self, identifier, *args).html_safe
5
+ end
6
+ end
7
+
8
+ ActionView::Base.include Helpers
9
+ end
@@ -0,0 +1,29 @@
1
+ module Haken
2
+ class Listeners
3
+ include Singleton
4
+
5
+ def self.subscribe(identifier, &block)
6
+ instance.subscribe(identifier, &block)
7
+ end
8
+
9
+ def self.load_hooks_for(identifier, *args)
10
+ instance.load_hooks_for(identifier, *args)
11
+ end
12
+
13
+ def initialize
14
+ @load_hooks = {}
15
+ end
16
+
17
+ def subscribe(identifier, &block)
18
+ @load_hooks[identifier] ||= []
19
+
20
+ @load_hooks[identifier] << block
21
+ end
22
+
23
+ def load_hooks_for(view_context, identifier)
24
+ @load_hooks[identifier].map do |hook|
25
+ view_context.instance_eval(&hook)
26
+ end.join
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Haken
2
+ VERSION = "0.1.0"
3
+ end
data/lib/haken.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'haken/version'
2
+ require 'haken/listeners'
3
+ require 'haken/helpers' if defined?(ActionView)
4
+
5
+ module Haken
6
+ def self.on_load(identifier, &block)
7
+ Listeners.subscribe(identifier, &block)
8
+ end
9
+
10
+ def load_hooks_for(identifier, *args)
11
+ Listeners.load_hooks_for(identifier, *args)
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: haken
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Davis Namsons
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-10-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Haken allows you to define places in your views where additional content
14
+ can be injected from elsewhere(for example, a seperate rails engine)
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - bin/console
26
+ - bin/setup
27
+ - haken.gemspec
28
+ - lib/haken.rb
29
+ - lib/haken/helpers.rb
30
+ - lib/haken/listeners.rb
31
+ - lib/haken/version.rb
32
+ homepage:
33
+ licenses:
34
+ - MIT
35
+ metadata: {}
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 2.3.0
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 3.0.3
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Add load hooks into your views
55
+ test_files: []