Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Namespaces for Better API Docs #4

Merged
merged 1 commit into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/motion/base.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "json"
require "./html_builder"
require "./html_engine"
require "./logger"
require "./exceptions"
require "./motions"
Expand All @@ -13,7 +13,7 @@ class Motion::Base
# setting render_component_comments : Bool = false
# end

include Motion::HTMLBuilder
include Motion::HTML::Engine
include Motion::Motions
include JSON::Serializable

Expand Down
1 change: 1 addition & 0 deletions src/motion/component_connection.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module Motion
# :nodoc:
class ComponentConnection
# TODO: Motion.serializer,
def self.from_state(state, serializer = Serializer.new, logger = Motion::Logger.new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
# ```
# h1 EmailAddress.new("myemail.com")
# ```
module Motion::AllowedInTags
module Motion::HTML::AllowedInTags
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# and allow for setting a CDN.
#
# For an in-depth guide check: https://luckyframework.org/guides/frontend/asset-handling
module Motion::AssetHelpers
module Motion::HTML::AssetHelpers
ASSET_MANIFEST = {} of String => String
CONFIG = {has_loaded_manifest: false}

Expand Down
2 changes: 1 addition & 1 deletion src/motion/assignable.cr → src/motion/html/assignable.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Motion::Assignable
module Motion::HTML::Assignable
# Declare what a page needs in order to be initialized.
#
# This will declare an instance variable and getter automatically. It will
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# :nodoc:
module Motion::HelpfulParagraphError
module Motion::HTML::HelpfulParagraphError
macro p(_arg, **args)
{% raise <<-ERROR
`p` is not available on Lucky pages. This is because it's not clear whether you want to print something out or use a `p` HTML tag.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# These helper methods will write directly to the view.
module Motion::HTMLTextHelpers
module Motion::HTML::HTMLTextHelpers
# Shortens text after a length point and inserts content afterward
#
# **Note: This method writes HTML directly to the page. It does not return a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Motion::NumberToCurrency
module Motion::HTML::NumberToCurrency
DEFAULT_PRECISION = 2
DEFAULT_UNIT = "$"
DEFAULT_SEPARATOR = "."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Motion::RenderIfDefined
module Motion::HTML::RenderIfDefined
macro render_if_defined(method_name)
if self.responds_to?(:{{ method_name.id }})
self.{{ method_name.id }}()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# These helper methods will return a `String`.
module Motion::TextHelpers
module Motion::HTML::TextHelpers
@@_cycles = Hash(String, Cycle).new

# Shorten text after a length point.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Motion::TimeHelpers
module Motion::HTML::TimeHelpers
# Returns a `String` with approximate distance in time between `from` and `to`.
#
# ```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Motion::UrlHelpers
module Motion::HTML::UrlHelpers
# Tests if the given path matches the current request path.
#
# ```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# :nodoc:
module Motion::CheckTagContent
module Motion::HTML::CheckTagContent
# If a tag has a nested tag (`IO`) or nil
# then return that content.
# ```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Motion::BaseTags
include Motion::CheckTagContent
module Motion::HTML::BaseTags
include Motion::HTML::CheckTagContent
TAGS = %i(a abbr address article aside b bdi body button code details dialog div dd dl dt em fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header html i iframe label li main mark menuitem meter nav ol option pre progress rp rt ruby s script section small span strong summary table tbody td template textarea th thead time title tr u ul video wbr)
RENAMED_TAGS = {"para": "p", "select_tag": "select"}
EMPTY_TAGS = %i(img br hr input meta source)
Expand All @@ -16,7 +16,7 @@ module Motion::BaseTags
# {{method_name.id}}("Sample", {"class" => "cls-1 red"}, [:required]) #=> <{{method_name.id}} class="cls-1 red" required>Sample</{{method_name.id}}>
# ```
def {{method_name.id}}(
content : Motion::AllowedInTags | String = "",
content : Motion::HTML::AllowedInTags | String = "",
options = EMPTY_HTML_ATTRS,
attrs : Array(Symbol) = [] of Symbol,
**other_options
Expand All @@ -27,7 +27,7 @@ module Motion::BaseTags
end
end

def {{method_name.id}}(content : String | Motion::AllowedInTags) : Nil
def {{method_name.id}}(content : String | Motion::HTML::AllowedInTags) : Nil
{{method_name.id}}(EMPTY_HTML_ATTRS) do
text content
end
Expand Down Expand Up @@ -97,8 +97,8 @@ module Motion::BaseTags
# text("Hello") # => Hello
# text("<div>") # => &lt;div&gt;
# ```
def text(content : String | Motion::AllowedInTags) : Nil
view << HTML.escape(content.to_s)
def text(content : String | Motion::HTML::AllowedInTags) : Nil
view << ::HTML.escape(content.to_s)
end

# Generates a `&lt;style&gt;&lt;/style&gt;` block for adding inline CSS
Expand All @@ -114,7 +114,7 @@ module Motion::BaseTags
tag_attrs = String.build do |attrs|
options.each do |key, value|
attrs << " " << Wordsmith::Inflector.dasherize(key.to_s) << "=\""
attrs << HTML.escape(value.to_s)
attrs << ::HTML.escape(value.to_s)
attrs << "\""
end
end
Expand All @@ -129,7 +129,7 @@ module Motion::BaseTags
end

private def merge_options(html_options, tag_attrs)
options = {} of String => String | Motion::AllowedInTags
options = {} of String => String | Motion::HTML::AllowedInTags
tag_attrs.each do |key, value|
options[key.to_s] = value
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#
# This module is included in the default `Shared::Field` component in new
# Lucky apps.
module Motion::CatchUnpermittedAttribute
module Motion::HTML::CatchUnpermittedAttribute
# :nodoc:
def self.new(field : Avram::Attribute, *arg, **named_args)
Motion::InputHelpers.error_message_for_unallowed_field
Motion::HTML::InputHelpers.error_message_for_unallowed_field
end
end
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Motion::CustomTags
include Motion::CheckTagContent
module Motion::HTML::CustomTags
include Motion::HTML::CheckTagContent
EMPTY_HTML_ATTRS = {} of String => String

def tag(
name : String,
content : Motion::AllowedInTags | String? = "",
content : Motion::HTML::AllowedInTags | String? = "",
options = EMPTY_HTML_ATTRS,
attrs : Array(Symbol) = [] of Symbol,
**other_options
Expand All @@ -16,7 +16,7 @@ module Motion::CustomTags
end
end

def tag(name : String, content : String | Motion::AllowedInTags) : Nil
def tag(name : String, content : String | Motion::HTML::AllowedInTags) : Nil
tag(EMPTY_HTML_ATTRS) do
text content
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Motion::ForgeryProtectionHelpers
module Motion::HTML::ForgeryProtectionHelpers
# Generate a hidden input with the request CSRF token
#
# This input is automatically generated when using
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Motion::InputHelpers
module Motion::HTML::InputHelpers
EMPTY_BOOLEAN_ATTRIBUTES = [] of Symbol

macro error_message_for_unallowed_field
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Motion::LabelHelpers
module Motion::HTML::LabelHelpers
def label_for(field : Avram::PermittedAttribute, text : String? = nil, **html_options) : Nil
label(
text || guess_label_name(field),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Motion::SelectHelpers
module Motion::HTML::SelectHelpers
def select_input(field : Avram::PermittedAttribute, **html_options) : Nil
select_tag merge_options(html_options, {"name" => input_name(field)}) do
yield
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Motion::SpecialtyTags
module Motion::HTML::SpecialtyTags
# Generates an HTML5 doctype tag.
def html_doctype : Nil
view << "<!DOCTYPE html>"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Set up defaults arguments for HTML tags.
#
# This is automatically included in Pages and Components.
module Motion::WithDefaults
module Motion::HTML::WithDefaults
# This is typically used in components and helper methods to set up defaults for
# reusable components.
#
Expand Down
46 changes: 23 additions & 23 deletions src/motion/html_builder.cr → src/motion/html_engine.cr
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
require "./tags/**"
require "./page_helpers/**"
require "./allowed_in_tags"
require "./asset_helpers"
require "./assignable"
require "./html/tags/**"
require "./html/page_helpers/**"
require "./html/allowed_in_tags"
require "./html/asset_helpers"
require "./html/assignable"
require "./mount_component"

module Motion::HTMLBuilder
include Motion::BaseTags
include Motion::CustomTags
include Motion::LabelHelpers
include Motion::InputHelpers
include Motion::SelectHelpers
include Motion::SpecialtyTags
include Motion::Assignable
include Motion::AssetHelpers
include Motion::NumberToCurrency
include Motion::TextHelpers
include Motion::HTMLTextHelpers
include Motion::TimeHelpers
include Motion::ForgeryProtectionHelpers
include Motion::MountComponent
include Motion::HelpfulParagraphError
include Motion::RenderIfDefined
include Motion::WithDefaults
module Motion::HTML::Engine
include BaseTags
include CustomTags
include LabelHelpers
include InputHelpers
include SelectHelpers
include SpecialtyTags
include Assignable
include AssetHelpers
include NumberToCurrency
include TextHelpers
include HTMLTextHelpers
include TimeHelpers
include ForgeryProtectionHelpers
include MountComponent
include HelpfulParagraphError
include RenderIfDefined
include WithDefaults

abstract def view
abstract def render
Expand Down
1 change: 1 addition & 0 deletions src/motion/html_transformer.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "myhtml"

module Motion
# :nodoc:
class HTMLTransformer
private property serializer : Motion::Serializer
private property key_attribute : String
Expand Down
1 change: 1 addition & 0 deletions src/motion/logger.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "log"

module Motion
# :nodoc:
class Logger
Log = ::Log.for("Motion")

Expand Down
1 change: 1 addition & 0 deletions src/motion/serializer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require "base64"
require "crypto/bcrypt"

module Motion
# :nodoc:
class Serializer
private HASH_PEPPER = "Motion"
private NULL_BYTE = "\0"
Expand Down