Skip to content

Instantly share code, notes, and snippets.

@bumble-bee-chuna
Created August 10, 2017 18:45
Show Gist options
  • Save bumble-bee-chuna/687289805ea45df1aab2045c4e2092ed to your computer and use it in GitHub Desktop.
Save bumble-bee-chuna/687289805ea45df1aab2045c4e2092ed to your computer and use it in GitHub Desktop.
module ApplicationHelper
$component_symbol_hash = {
'1' => "fa-check-square",
'2' => "fa-list",
'3' => "fa-cogs"
}
# Determine if subcomponent
def containsLetter(string_value)
string_value.count("a-zA-Z") > 0 ? true : false
end
# Remove component with description "General" from components
def remove_general_component(components)
index_of_general_component = components.index{ |item| item.name == "General" }
components.delete_at(index_of_general_component)
return components
end
# Sort components by description in desending order
def sort_components_by_description(components)
components = (components).sort! { |a, b| a.description <=> b.description }
end
# Retrieve components from project in desired format
def retrieve_components(project)
components = project.components
components = sort_components_by_description(components)
components = remove_general_component(components)
end
def open_or_close_unordered_list(previous_component, current_component)
# If the current component isn't a subcomponent AND the previous component was a subcomponent, end ul
if previous_component != {} and !containsLetter(current_component.description) and containsLetter(previous_component.description)
"</li></ul>"
# If the current component is a subcomponent AND the previous component wasn't, start ul
elsif containsLetter(current_component.description) and !containsLetter(previous_component.description)
"<ul class=\"nav nav-second-level collapse\">"
# Else return nothing
else
"</li>"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment