-
-
Save confact/0b07cd259a6fdfadd41008a5ffb72d02 to your computer and use it in GitHub Desktop.
add parameters depending on url
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
class LoaderComponent < BaseComponent | |
needs domain : Domain | |
needs period : String | |
needs url : String | |
needs goal : Goal? = nil | |
needs site_path : String = "" | |
needs source : String = "" | |
needs style : String = "" | |
def render | |
paramas = set_params | |
if paramas.nil? | |
div data_controller: "loader", data_loader_period: period, data_loader_url: "/domains/#{@domain.id}/#{url}", class: style | |
else | |
div **paramas, data_controller: "loader", data_loader_period: period, data_loader_url: "/domains/#{@domain.id}/#{url}", class: style | |
end | |
end | |
def set_params | |
params = Hash(Symbol, String | Int64).new | |
params[:data_loader_site_path] = site_path if !site_path.empty? | |
params[:data_source] = source if !source.empty? | |
params[:data_loader_goal] = goal.not_nil!.id if !goal.nil? | |
return nil if params.empty? | |
keys = params.keys | |
get_params_for_parameter(keys).from(params) | |
end | |
macro get_params_for_parameter(*keys) | |
NamedTuple({% for key in keys %} {{key.id}}: String | Int64, {% end %}) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment