sinatra-editable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,30 @@
1
+ sinatra-editable
2
+ ================
3
+
4
+ A simple extension to edit mostly static partials. The extension adds a get and put to '/editable/*', and provides an editable() helper.
5
+
6
+ For example:
7
+ If you put to '/editable/about-us/bio' textile text in params[:content], the extension will
8
+ write two files in in APP_ROOT/editable/about-us
9
+
10
+ The extension will parse the textile and save in 'bio.html', saving the original text in 'bio.textile'.
11
+
12
+ When you want to display the html, use the helper: editable("about-us/bio")
13
+
14
+ A more useful README coming soon :)
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), *%w[sinatra editable])
@@ -0,0 +1,79 @@
1
+ require 'sinatra/base'
2
+
3
+ module Sinatra
4
+ module Editable
5
+
6
+ module Helpers
7
+ def editable(item)
8
+ path = "#{options.root}/#{options.editable_dir}/#{item.to_s}.html"
9
+ if editable_exist?(item)
10
+ File.read(path)
11
+ end
12
+ end
13
+
14
+ def editable_exist?(item)
15
+ path = "#{options.root}/#{options.editable_dir}/#{item.to_s}.html"
16
+ File.exist?(path)
17
+ end
18
+ end
19
+
20
+ def self.registered(app)
21
+ app.helpers Editable::Helpers
22
+
23
+ app.set :editable_route, '/editable'
24
+ app.set :editable_dir, 'editable'
25
+ app.set :editable_templater, :html
26
+
27
+ app.get "/editable/*" do
28
+ path = "#{options.root}/#{options.editable_dir}/#{params[:splat].join('/')}.#{options.editable_templater}"
29
+ if File.exist?(path)
30
+ File.read(path)
31
+ else
32
+ 'new editable item..'
33
+ end
34
+ end
35
+
36
+ app.put "/editable/*" do
37
+ case options.editable_templater
38
+ when :textile
39
+ new_template = params[:content]
40
+ new_html = RedCloth.new(new_template).to_html
41
+ when :html
42
+ new_html = params[:content]
43
+ new_template = nil
44
+ else
45
+ raise "Bad templater option"
46
+ end
47
+
48
+ file_basename = params[:splat].pop.gsub(/\/$/,'')
49
+
50
+ dir = "#{options.root}/#{options.editable_dir}/#{params[:splat].join('/')}"
51
+
52
+ html_path = "#{dir}/#{file_basename}.html"
53
+ template_path = "#{dir}/#{file_basename}.#{options.editable_templater}"
54
+
55
+ FileUtils.mkdir_p dir unless File.exist?(File.dirname(dir))
56
+
57
+ if new_template
58
+ File.open(template_path,'w') do |f|
59
+ f.print(new_template)
60
+ f.close
61
+ end
62
+ end
63
+
64
+ File.open(html_path, 'w') do |f|
65
+ f.print(new_html)
66
+ f.close
67
+ end
68
+
69
+ new_html
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ register Editable
76
+ end
77
+
78
+
79
+ # create settings for route prefix, make helper to needed JS, which must be generated or with the proper route
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-editable
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Robert Crim
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-20 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: sinatra
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: redcloth
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :development
43
+ version_requirements: *id002
44
+ description: A simple CMS extension for sinatra
45
+ email: robert@osbornebrook.co.uk
46
+ executables: []
47
+
48
+ extensions: []
49
+
50
+ extra_rdoc_files: []
51
+
52
+ files:
53
+ - lib/sinatra/editable.rb
54
+ - lib/sinatra-editable.rb
55
+ - README
56
+ has_rdoc: true
57
+ homepage: http://github.com/ottbot/sinatra-editable
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.6
83
+ signing_key:
84
+ specification_version: 2
85
+ summary: A simple CMS extension for sinatra
86
+ test_files: []
87
+