Module: Card::Set::All::Head::HtmlFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
card/tmpsets/set/mod008-card-mod-format/all/head.rb,
card/tmpsets/set/mod007-card-mod-format/all/head.rb

Instance Method Summary collapse

Instance Method Details

#debug_or_machine_path(setting, &block) ⇒ Object



106
107
108
109
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 106

def debug_or_machine_path setting, &block
  return unless (asset_card = param_or_rule_card setting)
  debug_path(setting, asset_card, &block) || asset_card.machine_output_url
end

#debug_path(setting, asset_card) {|asset_card| ... } ⇒ Object

Yields:

  • (asset_card)


111
112
113
114
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 111

def debug_path setting, asset_card
  return unless params[:debug] == setting.to_s
  yield asset_card
end

#decko_script_variablesObject



78
79
80
81
82
83
84
85
86
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 78

def decko_script_variables
  {
    "window.decko": { rootUrl: card_url("") },
    "decko.doubleClick": Card.config.double_click,
    "decko.cssPath": head_stylesheet_path,
    "decko.currentUserId": (Auth.current_id if Auth.signed_in?)

  }
end

#head_javascript_pathsObject



122
123
124
125
126
127
128
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 122

def head_javascript_paths
  debug_or_machine_path :script do |script_card|
    script_card.item_cards.map do |script|
      script.format(:js).render :source
    end
  end
end

#head_stylesheet_pathObject



116
117
118
119
120
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 116

def head_stylesheet_path
  debug_or_machine_path :style do |style_card|
    path mark: style_card.name, item: :import, format: :css
  end
end

#mod_js_configsObject



136
137
138
139
140
141
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 136

def mod_js_configs
  mod_js_config.map do |codename, js_decko_function|
    config_json = escape_javascript Card::Rule.global_setting(codename)
    "decko.#{js_decko_function}('#{config_json}')"
  end
end

#param_or_rule_card(setting) ⇒ Object



98
99
100
101
102
103
104
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 98

def param_or_rule_card setting
  if params[setting]
    Card[params[setting]]
  else
    root.card.rule_card setting
  end
end

#rss_link?Boolean

Returns:

  • (Boolean)


152
153
154
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 152

def rss_link?
  Card.config.rss_enabled && respond_to?(:rss_link_tag)
end

#script_variable_to_js(value) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 88

def script_variable_to_js value
  if value.is_a? Hash
    string = "{"
    value.each { |k, v| string += "#{k}:#{script_variable_to_js v}" }
    string + "}"
  else
    "'#{value}'"
  end
end

#trigger_slot_readyObject



143
144
145
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 143

def trigger_slot_ready
  "$('document').ready(function() { $('.card-slot').trigger('slotReady'); })"
end

#view: decko_script_variablesObject



70
71
72
73
74
75
76
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 70

view :decko_script_variables, unknown: true, cache: :never, perms: :none do
  string = ""
  decko_script_variables.each do |k, v|
    string += "#{k}=#{script_variable_to_js v};\n"
  end
  javascript_tag { string }
end

#view: favicon_tagObject



46
47
48
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 46

view :favicon_tag, unknown: true, perms: :none do
  nest :favicon, view: :link_tag
end

#view: headObject



22
23
24
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 22

view :head, unknown: true, perms: :none do
  views_in_head.map { |viewname| render viewname }.flatten.compact.join "\n"
end

#view: head_javascriptObject



64
65
66
67
68
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 64

view :head_javascript, unknown: true, cache: :never, perms: :none do
  Array.wrap(head_javascript_paths).map do |path|
    javascript_include_tag path
  end
end

#view: head_stylesheetObject

these should render a view of the rule card it would then be safe to cache if combined with param handling (but note that machine clearing would need to reset card cache…)



59
60
61
62
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 59

view :head_stylesheet, unknown: true, cache: :never, perms: :none do
  return unless (href = head_stylesheet_path)
  tag "link", href: href, media: "all", rel: "stylesheet", type: "text/css"
end

#view: html5shiv_tagObject



38
39
40
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 38

view :html5shiv_tag, unknown: true, perms: :none do
  nest :script_html5shiv_printshiv, view: :script_tag
end

#view: meta_tagsObject

FIXME: tags not working with template: :haml



34
35
36
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 34

view :meta_tags, unknown: true, perms: :none do
  haml :meta_tags
end

#view: page_title_tagObject



42
43
44
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 42

view :page_title_tag, unknown: true, perms: :none do
  (:title) { render :page_title }
end

TODO: move to rss mod



148
149
150
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 148

view :rss_links, unknown: true, perms: :none do
  render :rss_link_tag if rss_link?
end

#view: script_config_and_initiationObject



130
131
132
133
134
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 130

view :script_config_and_initiation, unknown: true, perms: :none do
  javascript_tag do
    (mod_js_configs << trigger_slot_ready).join "\n\n"
  end
end

#view: universal_edit_buttonObject



50
51
52
53
54
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 50

view :universal_edit_button, unknown: true, denial: :blank, perms: :update do
  return if card.new?
  tag "link", rel: "alternate", type: "application/x-wiki",
              title: "Edit this page!", href: path(view: :edit)
end

#views_in_headObject



26
27
28
29
30
31
# File 'card/tmpsets/set/mod008-card-mod-format/all/head.rb', line 26

def views_in_head
  %i[meta_tags page_title_tag favicon_tag head_stylesheet
     decko_script_variables head_javascript html5shiv_tag
     script_config_and_initiation
     universal_edit_button rss_links]
end