Class: SidebarUrl

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/sidebar_url.rb

Constant Summary collapse

MAX_ICON_LENGTH =
40
MAX_NAME_LENGTH =
80
MAX_VALUE_LENGTH =
1000
[
  {
    name: "Topics",
    path: "/latest",
    icon: "layer-group",
    segment: SidebarUrl.segments["primary"],
  },
  {
    name: "My Posts",
    path: "/my/activity",
    icon: "user",
    segment: SidebarUrl.segments["primary"],
  },
  { name: "Review", path: "/review", icon: "flag", segment: SidebarUrl.segments["primary"] },
  { name: "Admin", path: "/admin", icon: "wrench", segment: SidebarUrl.segments["primary"] },
  {
    name: "Invite",
    path: "/new-invite",
    icon: "paper-plane",
    segment: SidebarUrl.segments["primary"],
  },
  { name: "Users", path: "/u", icon: "users", segment: SidebarUrl.segments["secondary"] },
  {
    name: "About",
    path: "/about",
    icon: "circle-info",
    segment: SidebarUrl.segments["secondary"],
  },
  {
    name: "FAQ",
    path: "/faq",
    icon: "circle-question",
    segment: SidebarUrl.segments["secondary"],
  },
  { name: "Groups", path: "/g", icon: "user-group", segment: SidebarUrl.segments["secondary"] },
  {
    name: "Badges",
    path: "/badges",
    icon: "certificate",
    segment: SidebarUrl.segments["secondary"],
  },
]

Instance Method Summary collapse

Instance Method Details

#path_validatorObject



60
61
62
63
64
65
66
67
68
# File 'app/models/sidebar_url.rb', line 60

def path_validator
  return true if !external?
  raise ActionController::RoutingError.new("Not Found") if value !~ Discourse::Utils::URI_REGEXP
rescue ActionController::RoutingError
  errors.add(
    :value,
    I18n.t("activerecord.errors.models.sidebar_section_link.attributes.linkable_type.invalid"),
  )
end

#remove_internal_hostnameObject



70
71
72
# File 'app/models/sidebar_url.rb', line 70

def remove_internal_hostname
  self.value = self.value.sub(%r{\Ahttp(s)?://#{Discourse.current_hostname}}, "")
end

#set_externalObject



74
75
76
# File 'app/models/sidebar_url.rb', line 74

def set_external
  self.external = value.start_with?("http://", "https://")
end