fredit 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,10 +22,6 @@ edit page.
22
22
 
23
23
  You can also create and delete front-end files on the fredit edit page.
24
24
 
25
- **NOTE: Currently only the ERB Rails template handler is supported.**
26
- You are welcome to fork and add support for Haml and other template
27
- handlers.
28
-
29
25
 
30
26
  ## fredit lowers the barriers to collaboration
31
27
 
@@ -50,7 +46,7 @@ templates and stylesheets. This is madness. And if you want to add
50
46
  additional non-Rails people as front-end collaborators, [the King of
51
47
  Sparta kicks you into a pit][sparta]. Have fun.
52
48
 
53
- [sparta]:http://www.youtube.com/watch?v=-qR0Uke2XNI
49
+ [sparta]:http://www.youtube.com/watch?v=wDiUG52ZyHQ&t=38s
54
50
 
55
51
  Another option is to integrate a CMS into your Rails app. But in
56
52
  addition to adding a mass of dependencies and code bloat, this approach
@@ -94,7 +90,8 @@ lower the "collaboration barrier" to reap further gains in productivity.
94
90
 
95
91
  ## Install and setup
96
92
 
97
- fredit requires Rails 3.
93
+ fredit requires Rails 3. fredit should work with all Rails-compatible
94
+ templating engines as of version 0.2.0.
98
95
 
99
96
  fredit works best as a gem you include in a specific Rails
100
97
  environment. Put something like this in the `Gemfile` of your Rails app:
data/lib/fredit.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  if Rails.version < '3.1.0'
2
- require 'fredit/erb'
2
+ require 'fredit/template30'
3
3
  else
4
- require 'fredit/erb31'
4
+ require 'fredit/template31'
5
5
  end
6
6
  require 'uri'
7
7
 
@@ -35,12 +35,27 @@ module Fredit
35
35
  {:css => css, :views => views, :javascript => js}
36
36
  end
37
37
 
38
+ def add_fredit_link(template, s)
39
+ return s unless template_editable?(template)
40
+ if s =~ /^\s*<!DOCTYPE/ && s =~ /<body[^>]*>/
41
+ s.sub(/<body[^>]*>/, '\&' + fredit_link(template))
42
+ else
43
+ fredit_link(template) + s
44
+ end
45
+ end
46
+
47
+ def fredit_link(template)
48
+ source_file = Fredit.rel_path template.identifier
49
+ edit_link = "<div style='color:red'>#{Fredit.link(source_file)}</div>".html_safe
50
+ end
51
+
38
52
  def template_editable?(template)
39
53
  template.identifier.index(Rails.root.to_s) == 0 &&
40
54
  template.formats &&
41
55
  template.formats.include?(:html)
42
56
  end
43
57
 
58
+
44
59
  end
45
60
 
46
61
  require 'fredit/engine'
@@ -0,0 +1,28 @@
1
+ module ActionView
2
+ class Template
3
+
4
+ def render(view, locals, &block)
5
+ # Notice that we use a bang in this instrumentation because you don't want to
6
+ # consume this in production. This is only slow if it's being listened to.
7
+ ActiveSupport::Notifications.instrument("!render_template.action_view", :virtual_path => @virtual_path) do
8
+ if view.is_a?(ActionView::CompiledTemplates)
9
+ mod = ActionView::CompiledTemplates
10
+ else
11
+ mod = view.singleton_class
12
+ end
13
+ method_name = compile(locals, view, mod)
14
+ r = view.send(method_name, locals, &block)
15
+ Fredit.add_fredit_link(self, r)
16
+ end
17
+ rescue Exception => e
18
+ if e.is_a?(Template::Error)
19
+ e.sub_template_of(self)
20
+ raise e
21
+ else
22
+ raise Template::Error.new(self, view.respond_to?(:assigns) ? view.assigns : {}, e)
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+
@@ -0,0 +1,16 @@
1
+ module ActionView
2
+ class Template
3
+ def render(view, locals, buffer=nil, &block)
4
+ ActiveSupport::Notifications.instrument("!render_template.action_view", :virtual_path => @virtual_path) do
5
+ compile!(view)
6
+ r = view.send(method_name, locals, buffer, &block)
7
+ Fredit.add_fredit_link(self, r)
8
+ end
9
+ rescue Exception => e
10
+ handle_render_error(view, e)
11
+ end
12
+ end
13
+ end
14
+
15
+ __END__
16
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fredit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: git
16
- requirement: &70199512506440 !ruby/object:Gem::Requirement
16
+ requirement: &72582790 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70199512506440
24
+ version_requirements: *72582790
25
25
  description: Edit the front end of Rails apps through the browser.
26
26
  email:
27
27
  - dhchoi@gmail.com
@@ -29,14 +29,14 @@ executables: []
29
29
  extensions: []
30
30
  extra_rdoc_files: []
31
31
  files:
32
- - app/controllers/fredit_controller.rb
33
- - app/views/fredit/revision.html.erb
34
- - app/views/fredit/show.html.erb
35
32
  - app/views/layouts/fredit.html.erb
36
- - lib/fredit/engine.rb
37
- - lib/fredit/erb.rb
38
- - lib/fredit/erb31.rb
33
+ - app/views/fredit/show.html.erb
34
+ - app/views/fredit/revision.html.erb
35
+ - app/controllers/fredit_controller.rb
39
36
  - lib/fredit.rb
37
+ - lib/fredit/template31.rb
38
+ - lib/fredit/template30.rb
39
+ - lib/fredit/engine.rb
40
40
  - config/routes.rb
41
41
  - MIT-LICENSE
42
42
  - Rakefile
@@ -56,7 +56,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
56
  version: '0'
57
57
  segments:
58
58
  - 0
59
- hash: 1023881741045697263
59
+ hash: 421214845
60
60
  required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
@@ -65,10 +65,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  version: '0'
66
66
  segments:
67
67
  - 0
68
- hash: 1023881741045697263
68
+ hash: 421214845
69
69
  requirements: []
70
70
  rubyforge_project:
71
- rubygems_version: 1.8.6
71
+ rubygems_version: 1.8.11
72
72
  signing_key:
73
73
  specification_version: 3
74
74
  summary: Edit the front end of Rails apps through the browser.
data/lib/fredit/erb.rb DELETED
@@ -1,50 +0,0 @@
1
- module ActionView
2
- class Template
3
- module Handlers
4
- class ERB < Handler
5
- def compile(template)
6
-
7
- # copied from original
8
-
9
- if template.source.encoding_aware?
10
- # First, convert to BINARY, so in case the encoding is
11
- # wrong, we can still find an encoding tag
12
- # (<%# encoding %>) inside the String using a regular
13
- # expression
14
- template_source = template.source.dup.force_encoding("BINARY")
15
-
16
- erb = template_source.gsub(ENCODING_TAG, '')
17
- encoding = $2
18
-
19
- erb.force_encoding valid_encoding(template.source.dup, encoding)
20
-
21
- # Always make sure we return a String in the default_internal
22
- erb.encode!
23
- else
24
- erb = template.source.dup
25
- end
26
-
27
- # begin Fredit patch
28
-
29
- if Fredit.template_editable?(template)
30
- source_file = Fredit.rel_path template.identifier
31
- edit_link = "<div style='color:red'>#{Fredit.link(source_file)}</div> "
32
- if erb =~ /^\s*<!DOCTYPE/ && erb =~ /<body[^>]*>/
33
- erb = erb.sub(/<body[^>]*>/, '\&' + edit_link)
34
- else
35
- erb = edit_link + erb
36
- end
37
- end
38
-
39
- # end Fredit patch
40
-
41
- self.class.erb_implementation.new(
42
- erb,
43
- :trim => (self.class.erb_trim_mode == "-")
44
- ).src
45
- end
46
-
47
- end
48
- end
49
- end
50
- end
data/lib/fredit/erb31.rb DELETED
@@ -1,50 +0,0 @@
1
- module ActionView
2
- class Template
3
- module Handlers
4
- class ERB
5
- def call(template)
6
- if template.source.encoding_aware?
7
- # First, convert to BINARY, so in case the encoding is
8
- # wrong, we can still find an encoding tag
9
- # (<%# encoding %>) inside the String using a regular
10
- # expression
11
- template_source = template.source.dup.force_encoding("BINARY")
12
-
13
- erb = template_source.gsub(ENCODING_TAG, '')
14
- encoding = $2
15
-
16
- erb.force_encoding valid_encoding(template.source.dup, encoding)
17
-
18
- # Always make sure we return a String in the default_internal
19
- erb.encode!
20
- else
21
- erb = template.source.dup
22
- end
23
-
24
- # begin Fredit patch
25
-
26
- if Fredit.template_editable?(template)
27
- source_file = Fredit.rel_path template.identifier
28
- edit_link = "<div style='color:red'>#{Fredit.link(source_file)}</div> "
29
- if erb =~ /^\s*<!DOCTYPE/ && erb =~ /<body[^>]*>/
30
- erb = erb.sub(/<body[^>]*>/, '\&' + edit_link)
31
- else
32
- erb = edit_link + erb
33
- end
34
- end
35
-
36
- # end Fredit patch
37
-
38
-
39
- self.class.erb_implementation.new(
40
- erb,
41
- :trim => (self.class.erb_trim_mode == "-")
42
- ).src
43
-
44
- end
45
-
46
- end
47
- end
48
- end
49
- end
50
-