Module: Fredit

Extended by:
Fredit
Included in:
Fredit
Defined in:
lib/fredit.rb,
lib/fredit/engine.rb,
lib/fredit/version.rb

Defined Under Namespace

Classes: Engine

Constant Summary collapse

"margin:0;margin-top:-1em;padding:1px;font-size:10px;background-color:#a3f66c;border:1px solid #666;"
VERSION =
'0.2.8'

Instance Method Summary collapse

Instance Method Details



40
41
42
43
44
45
46
47
# File 'lib/fredit.rb', line 40

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

#editablesObject



32
33
34
35
36
37
38
# File 'lib/fredit.rb', line 32

def editables
  prefix = File.directory?(Rails.root + 'app/assets') ? 'app/assets' : 'public'
  css = entries(prefix + '/stylesheets/*') 
  js = entries(prefix + '/javascripts/*')
  views = entries('app/views/**/*.html.*')
  {:css => css, :views => views, :javascript => js}
end

#entries(glob) ⇒ Object



28
29
30
# File 'lib/fredit.rb', line 28

def entries(glob)
  Dir[glob].entries.map {|e| rel_path(e)}
end


49
50
51
52
# File 'lib/fredit.rb', line 49

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

TODO change this to be compatible with HAML



23
24
25
26
# File 'lib/fredit.rb', line 23

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



14
15
16
# File 'lib/fredit.rb', line 14

def rel_path(path)
  path.sub(Rails.root.to_s + '/', '')
end

#rel_paths(paths) ⇒ Object



18
19
20
# File 'lib/fredit.rb', line 18

def rel_paths(paths)
  paths.map {|x| rel_path(x)}
end

#template_editable?(template) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
# File 'lib/fredit.rb', line 54

def template_editable?(template)
  template.identifier.index(Rails.root.to_s) == 0 &&
    template.formats && 
    template.formats.include?(:html)
end