-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from luckyframework/matthewmcgarvey/extension-…
…registration First pass at extension registration
- Loading branch information
Showing
6 changed files
with
64 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,15 @@ | ||
class Breeze::NavbarLinks < Breeze::BreezeComponent | ||
needs context : HTTP::Server::Context | ||
|
||
Habitat.create do | ||
setting links : Array(Proc(Breeze::NavbarLinks, Nil)) = [ | ||
->(navbar : Breeze::NavbarLinks) { | ||
navbar.mount_link("Requests", to: Breeze::Requests::Index) | ||
}, | ||
->(navbar : Breeze::NavbarLinks) { | ||
navbar.mount_link("Queries", to: Breeze::Queries::Index) | ||
}, | ||
] | ||
end | ||
|
||
def render | ||
settings.links.each do |component| | ||
component.call(self) | ||
mount_link("Requests", to: Breeze::Requests::Index) | ||
mount_link("Queries", to: Breeze::Queries::Index) | ||
Breeze.extensions.each do |extension| | ||
mount extension.navbar_link(context) | ||
end | ||
end | ||
|
||
def mount_link(link_text : String, to action : Lucky::Action.class) | ||
private def mount_link(link_text : String, to action : Lucky::Action.class) | ||
mount(Breeze::NavbarLink, context: context, link_text: link_text, link_to: action.path) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,24 @@ | ||
abstract class Breeze::BreezeComponent < Lucky::BaseComponent | ||
include Lucky::UrlHelpers | ||
alias HtmlProc = Proc(IO::Memory) | Proc(Nil) | ||
|
||
def mount(component : Lucky::BaseComponent, *args, **named_args) : Nil | ||
print_component_comment(component) do | ||
component.view(view).render | ||
end | ||
end | ||
|
||
def mount(component : Lucky::BaseComponent, *args, **named_args) : Nil | ||
print_component_comment(component) do | ||
component.view(view).render do |*yield_args| | ||
yield *yield_args | ||
end | ||
end | ||
end | ||
|
||
private def print_component_comment(component : Lucky::BaseComponent) : Nil | ||
print_component_comment(component.class) do | ||
yield | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# To create an extension you must extend this module | ||
# | ||
# Example: | ||
# ``` | ||
# module BreezeCustom | ||
# extend Breeze::Extension | ||
# | ||
# def self.navbar_link(context : HTTP::Server::Context) : Breeze::NavbarLink | ||
# Breeze::NavbarLink.new(context: context, link_text: "Custom", link_to: BreezeCustom::Index.path) | ||
# end | ||
# end | ||
# ``` | ||
# | ||
# Projects that want to use this extension will need to register it | ||
# | ||
# ``` | ||
# Breeze.register BreezeCustom | ||
# ``` | ||
# | ||
module Breeze::Extension | ||
abstract def navbar_link(context : HTTP::Server::Context) : Breeze::NavbarLink | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters