Module: MailerTags
- Includes:
- ActionView::Helpers::DateHelper, ActionView::Helpers::TagHelper, Radiant::Taggable
- Defined in:
- lib/mailer_tags.rb
Instance Method Summary collapse
- #add_required(result, tag) ⇒ Object
- #detect_date(mail, name) ⇒ Object
- #format_mailer_data(element, name) ⇒ Object
- #mailer_attrs(tag, extras = {}) ⇒ Object
- #mailer_config(mailer_page = self) ⇒ Object
- #prior_value(tag, tag_name = ) ⇒ Object
- #raise_error_if_name_missing(tag_name, tag_attr) ⇒ Object
Instance Method Details
#add_required(result, tag) ⇒ Object
383 384 385 386 |
# File 'lib/mailer_tags.rb', line 383 def add_required(result, tag) result << %(<input type="hidden" name="mailer[required][#{tag.attr['name']}]" value="#{tag.attr['required']}" />) if tag.attr['required'] result.flatten.join end |
#detect_date(mail, name) ⇒ Object
323 324 325 326 327 328 329 330 331 332 |
# File 'lib/mailer_tags.rb', line 323 def detect_date(mail, name) date_components = mail.select { |key, value| key =~ Regexp.new("#{name}\\(\\di\\)") } if date_components.length == 3 date_values = date_components.sort { |a, b| a[0] <=> b[0] }.map { |v| v[1].to_i } return Date.new(*date_values) else return nil end end |
#format_mailer_data(element, name) ⇒ Object
312 313 314 315 316 317 318 319 320 321 |
# File 'lib/mailer_tags.rb', line 312 def format_mailer_data(element, name) data = element[name] if Array === data data.to_sentence elsif date = detect_date(element, name) date else data end end |
#mailer_attrs(tag, extras = {}) ⇒ Object
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/mailer_tags.rb', line 343 def mailer_attrs(tag, extras={}) attrs = { 'accept' => nil, 'accesskey' => nil, 'alt' => nil, 'autocomplete' => nil, 'autofocus' => nil, 'checked' => nil, 'class' => nil, 'contextmenu' => nil, 'dir' => nil, 'disabled' => nil, 'height' => nil, 'hidden' => nil, 'id' => tag.attr['name'], 'lang' => nil, 'max' => nil, 'maxlength' => nil, 'min' => nil, 'pattern' => nil, 'placeholder' => nil, 'size' => nil, 'spellcheck' => nil, 'step' => nil, 'style' => nil, 'tabindex' => nil, 'title' => nil, 'width' => nil}.merge(extras) result = attrs.sort.collect do |k,v| v = (tag.attr[k] || v) if k == 'class' && tag.attr['required'].present? v = [v, 'required', tag.attr['required']].compact.join(' ') end next if v.blank? %(#{k}="#{v}") end.reject{|e| e.blank?} result << %(name="mailer[#{tag.attr['name']}]") unless tag.attr['name'].blank? result.join(' ') end |
#mailer_config(mailer_page = self) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/mailer_tags.rb', line 6 def mailer_config(mailer_page=self) @mailer_config ||= begin page = mailer_page until page.part(:mailer) or (not page.parent) page = page.parent end string = page.render_part(:mailer) (string.empty? ? {} : YAML::load(string)) end end |
#prior_value(tag, tag_name = ) ⇒ Object
334 335 336 337 338 339 340 341 |
# File 'lib/mailer_tags.rb', line 334 def prior_value(tag, tag_name=tag.attr['name']) if mail = tag.locals.page.last_mail h(mail.data[tag_name]) unless StringIO === mail.data[tag_name] or Tempfile === mail.data[tag_name] else nil end end |
#raise_error_if_name_missing(tag_name, tag_attr) ⇒ Object
388 389 390 |
# File 'lib/mailer_tags.rb', line 388 def raise_error_if_name_missing(tag_name, tag_attr) raise "`#{tag_name}' tag requires a `name' attribute" if tag_attr['name'].blank? end |