Module: SparkleHelpers

Defined in:
lib/orange-sparkles/sparkles_app.rb

Instance Method Summary collapse

Instance Method Details

#button(text, link, opts = {}) ⇒ Object



102
103
104
105
106
107
108
109
# File 'lib/orange-sparkles/sparkles_app.rb', line 102

def button(text, link, opts = {})
  opts.with_defaults!({:css_class => "grey-button", :method => 'POST', :confirm => false})
  if opts[:confirm]
    "<form method='POST' class='mini-form' action='#{link}'><input name='_method' type='hidden' value='#{opts[:method]}' /><a class='#{opts[:css_class]} button' onclick='if(confirm(\"#{opts[:confirm]}\")){ $(this).parent().submit(); }; return false;' href='#{link}'>#{text}</a></form>"
  else
    "<form method='POST' class='mini-form' action='#{link}'><input name='_method' type='hidden' value='#{opts[:method]}' /><a class='#{opts[:css_class]} button' onclick='$(this).parent().submit(); return false;' href='#{link}'>#{text}</a></form>"
  end
end

#delete_button(link) ⇒ Object



110
111
112
# File 'lib/orange-sparkles/sparkles_app.rb', line 110

def delete_button(link)
  button("Delete", link, {:css_class => "delete-button", :method => "DELETE", :confirm => "Are you sure you want to delete this?"})
end

#lorem(chars = 300) ⇒ Object



96
97
98
99
100
101
# File 'lib/orange-sparkles/sparkles_app.rb', line 96

def lorem(chars = 300)
  chars = chars.to_i
  ("Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tincidunt enim eget ante semper  interdum. Proin quis erat nec tellus faucibus volutpat. Aenean ornare augue eu tellus fermentum vel blandit ipsum bibendum. Pellentesque a nisi justo, non tristique metus. Curabitur fermentum tincidunt neque, sit amet posuere dui tempor at. Suspendisse imperdiet lobortis tempus. Nulla ac sem ut lorem laoreet porttitor at vestibulum dui.

  Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tincidunt enim eget ante semper interdum. Proin quis erat nec tellus faucibus volutpat. Aenean ornare augue eu tellus fermentum vel blandit ipsum bibendum."*6)[0..chars]
end

#markdown(string) ⇒ Object



91
92
93
94
95
# File 'lib/orange-sparkles/sparkles_app.rb', line 91

def markdown(string)
  # Preparse for radius
  # string = orange[:radius].parse_text(self, string)
  Kramdown::Document.new(string).to_html
end

#move_button(dir, route) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/orange-sparkles/sparkles_app.rb', line 113

def move_button(dir, route)
  action = packet.route_to(:sitemap, route.id, dir)
  case dir
  when "outdent"
    disabled = true unless route.level > 1 
  when "indent"
    disabled = true unless route.previous_sibling
  when "higher"
    disabled = true unless route.previous_sibling
  when "lower"
    disabled = true unless route.next_sibling
  end
  unless disabled
    return "<form method='POST' class='move-arrow' action='#{action}'><a href='#{action}' class='move-#{dir}' onclick=''><img src='/assets/_sparkles_/images/move-#{dir}.png' /></a></form>"
  else return "<a class='move-#{dir} move-disabled'><img src='/assets/_sparkles_/images/move-#{dir}-disabled.png' /></a>"
  end
end