Module: Fredit
Defined Under Namespace
Classes: Engine
Constant Summary collapse
- LINK_CSS =
"margin:0;margin-top:-1em;padding:1px;font-size:10px;background-color:#a3f66c;border:1px solid #666;"
Instance Method Summary collapse
- #add_fredit_link(template, s) ⇒ Object
- #editables ⇒ Object
- #entries(glob) ⇒ Object
- #fredit_link(template) ⇒ Object
-
#link(x) ⇒ Object
TODO change this to be compatible with HAML.
- #rel_path(path) ⇒ Object
- #rel_paths(paths) ⇒ Object
- #template_editable?(template) ⇒ Boolean
Instance Method Details
#add_fredit_link(template, s) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/fredit.rb', line 38 def add_fredit_link(template, s) return s unless template_editable?(template) if s =~ /^\s*<!DOCTYPE/ && s =~ /<body[^>]*>/ s.sub(/<body[^>]*>/, '\&' + fredit_link(template)) else fredit_link(template) + s end end |
#editables ⇒ Object
31 32 33 34 35 36 |
# File 'lib/fredit.rb', line 31 def editables css = entries('public/**/*.css') js = entries('public/**/*.js') views = entries('app/views/**/*.html.*') {:css => css, :views => views, :javascript => js} end |
#entries(glob) ⇒ Object
27 28 29 |
# File 'lib/fredit.rb', line 27 def entries(glob) Dir[Rails.root + glob].entries.map {|e| rel_path(e)} end |
#fredit_link(template) ⇒ Object
47 48 49 50 |
# File 'lib/fredit.rb', line 47 def fredit_link(template) source_file = Fredit.rel_path template.identifier edit_link = "<div style='color:red'>#{Fredit.link(source_file)}</div>".html_safe end |
#link(x) ⇒ Object
TODO change this to be compatible with HAML
22 23 24 25 |
# File 'lib/fredit.rb', line 22 def link(x) s = %Q| <a style="#{LINK_CSS}" href="/fredit?file=#{URI.escape(x)}" target="_blank">#{x}</a> | s.strip.html_safe end |
#rel_path(path) ⇒ Object
13 14 15 |
# File 'lib/fredit.rb', line 13 def rel_path(path) path.sub(Rails.root.to_s + '/', '') end |
#rel_paths(paths) ⇒ Object
17 18 19 |
# File 'lib/fredit.rb', line 17 def rel_paths(paths) paths.map {|x| rel_path(x)} end |
#template_editable?(template) ⇒ Boolean
52 53 54 55 56 |
# File 'lib/fredit.rb', line 52 def template_editable?(template) template.identifier.index(Rails.root.to_s) == 0 && template.formats && template.formats.include?(:html) end |