class ProjectCustomStyle::Hooks

Constants

STYLE_WRAPPER

Public Instance Methods

view_layouts_base_html_head(context) click to toggle source
# File lib/project_custom_style/hooks.rb, line 5
def view_layouts_base_html_head(context)
  page = find_wiki_page(context)
  wrap_style_content(page.content.text) if page
end
view_projects_contextual(context) click to toggle source
# File lib/project_custom_style/hooks.rb, line 10
def view_projects_contextual(context)
  link_to(
    l("project_custom_style_label"),
    edit_path(context),
    class: "icon icon-copy"
  )
end

Private Instance Methods

custom_style_wiki_page() click to toggle source
# File lib/project_custom_style/hooks.rb, line 27
def custom_style_wiki_page
  settings["page"]
end
edit_path(context) click to toggle source
# File lib/project_custom_style/hooks.rb, line 20
def edit_path(context)
  edit_project_wiki_page_path(
    project_id: context[:project].id,
    id: custom_style_wiki_page
  )
end
find_wiki_page(context) click to toggle source
# File lib/project_custom_style/hooks.rb, line 35
def find_wiki_page(context)
  (project = context[:project]) &&
    project.wiki &&
    project.wiki.find_page(custom_style_wiki_page)
end
settings() click to toggle source
# File lib/project_custom_style/hooks.rb, line 31
def settings
  Setting.plugin_project_custom_style
end
starts_with_style_or_script_tag?(text) click to toggle source
# File lib/project_custom_style/hooks.rb, line 49
def starts_with_style_or_script_tag?(text)
  text =~ /\A\s*<(style|script)/
end
wrap_style_content(text) click to toggle source
# File lib/project_custom_style/hooks.rb, line 41
def wrap_style_content(text)
  if starts_with_style_or_script_tag?(text)
    text
  else
    STYLE_WRAPPER % text
  end
end