Permalink
Fetching contributors…
Cannot retrieve contributors at this time
76 lines (74 sloc) 3 KB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="/js/highlight.js"></script>
<script src="/js/languages/ruby.js"></script>
<script src="/js/options.js"></script>
<link rel="stylesheet" href="/css/reset.css" type="text/css" media="screen">
<link rel="stylesheet" href="/css/main.css" type="text/css" media="screen">
<link rel="stylesheet" href="/css/options.css" type="text/css" media="screen">
<title>Sight Options</title>
</head>
<body class="highlight">
<div>
<h3>Select your theme</h3>
<select name="theme" id="theme">
<option value="sunburst">SunBurst</option>
<option value="ir_black">IRBlack</option>
<option value="default">Default</option>
<option value="ascetic">Ascetic</option>
<option value="far">Far</option>
<option value="vs">Vs</option>
<option value="github">GitHub</option>
<option value="zenburn">ZenBurn</option>
<option value="idea">Idea</option>
<option value="dark">Dark</option>
<option value="magula">Magula</option>
</select>
<h3>Select your font</h3>
<select name="font" id="font">
<option value="Inconsolata">Inconsolata</option>
<option value="Courier New">Courier New</option>
<option value="Monaco">Monaco</option>
<option value="Anonymous Pro">Anonymous Pro</option>
<option value="DejaVuSansMono">DejaVu Sans Mono</option>
<option value="DroidSansMono">Droid Sans Mono</option>
<option value="Monofur">Monofur</option>
<option value="ProFont">ProFont</option>
<option value="ProggyClean">Proggy Clean</option>
<option value="Consolas">Consolas</option>
</select>
<h3>Show line numbers? <input type="checkbox" id="show-line-numbers" /></h3>
<div class="clear"></div>
<ul id="line-numbers"><li>01</li><li>02</li><li>03</li><li>04</li><li>05</li><li>06</li><li>07</li><li>08</li><li>09</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li></ul>
<pre>
<code class="ruby">
module Pluma
module Models
def self.included(base)
# base.send :include, InstanceMethods
base.extend ClassMethods
end
module ClassMethods
def has_permalink
before_save do |obj|
return if obj.permalink.to_s == obj.name.parameterize
obj.permalink = obj.name.parameterize
last_num = obj.class.select(:permalink).where([&quot;permalink like ?&quot;, obj.permalink + &#x27;%&#x27;])
last_num = last_num.order(&#x27;permalink desc&#x27;).first.try :permalink
unless last_num.blank?
last_num = last_num.match(/.*\-(\d+)$/)
last_num = last_num.blank? ? 1 : last_num[1].to_i + 1
obj.permalink += &quot;-#{last_num}&quot;
end
end
end
end
end
end
</code>
</pre>
</div>
</body>
</html>