Module: Marksmith::MarksmithHelper

Defined in:
app/helpers/marksmith/marksmith_helper.rb

Instance Method Summary collapse

Instance Method Details

#marksmith_asset_tags(*args, **kwargs) ⇒ Object



17
18
19
20
# File 'app/helpers/marksmith/marksmith_helper.rb', line 17

def marksmith_asset_tags(*args, **kwargs)
  stylesheet_link_tag("marksmith", *args, **kwargs) +
  javascript_include_tag("marksmith.esm.js", *args, **kwargs)
end

#marksmith_button_classesObject



22
23
24
25
26
27
# File 'app/helpers/marksmith/marksmith_helper.rb', line 22

def marksmith_button_classes
  class_names(
    "ms:flex ms:items:center ms:cursor-pointer ms:py-1 ms:px-1.5 ms:hover:bg-neutral-200 ms:rounded",
    "ms:dark:text-neutral-300 ms:dark:hover:bg-neutral-600"
  )
end

#marksmith_inline_svg(path) ⇒ Object



54
55
56
# File 'app/helpers/marksmith/marksmith_helper.rb', line 54

def marksmith_inline_svg(path)
  File.open(Marksmith::Engine.root.join(path)).read.html_safe
end

#marksmith_tab_classesObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/helpers/marksmith/marksmith_helper.rb', line 39

def marksmith_tab_classes
  class_names(
    # marksmith_button_classes,
    "marksmith-toggle-button ms:text-sm ms:hover:bg-neutral-300 ms:text-sm ms:font-medium ms:cursor-pointer ms:text-neutral-500 ms:px-3",
    # borders
    "ms:bg-transparent ms:hover:bg-transparent",
    "ms:-my-px ms:-ml-px ms:border ms:border-transparent",
    "ms:h-[calc(100%+3px)] ms:border-b-none",
    # "ms:border-b-neutral-00",
    # active classes
    "ms:[.active]:bg-neutral-50 ms:[.active]:text-neutral-900 ms:dark:[.active]:text-neutral-300 ms:[.active]:dark:bg-neutral-800 ms:[.active]:dark:border-neutral-500 ms:[.active]:rounded-t-md ms:[.active]:border-neutral-500",

  )
end

#marksmith_tag(name, **kwargs, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'app/helpers/marksmith/marksmith_helper.rb', line 7

def marksmith_tag(name, **kwargs, &block)
  rails_direct_uploads_url = if defined?(ActiveStorage)
    main_app.rails_direct_uploads_url
  end

  editor = Marksmith::Editor.new(name:, rails_direct_uploads_url:, **kwargs, &block)

  render partial: "marksmith/shared/editor", locals: { name: editor.name, editor: }
end

#marksmith_toolbar_button(name, hotkey_scope: nil, hotkey: nil, **kwargs) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'app/helpers/marksmith/marksmith_helper.rb', line 29

def marksmith_toolbar_button(name, hotkey_scope: nil, hotkey: nil, **kwargs)
   "md-#{name}", marksmith_toolbar_svg(name),
    title: t("marksmith.#{name.to_s.gsub("-", "_")}").humanize,
    class: marksmith_button_classes,
    data: {
      hotkey_scope:,
      hotkey:
    }
end

#marksmith_toolbar_svg(name) ⇒ Object

TODO: maybe inline svgs in the future



59
60
61
62
63
# File 'app/helpers/marksmith/marksmith_helper.rb', line 59

def marksmith_toolbar_svg(name)
  marksmith_inline_svg("app/assets/images/marksmith/svgs/#{name}.svg")
rescue
  "<!-- Failed to load SVG for #{name} -->"
end

#marksmithed(body) ⇒ Object



3
4
5
# File 'app/helpers/marksmith/marksmith_helper.rb', line 3

def marksmithed(body)
  Marksmith::Renderer.new(body:).render
end