copy 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Javan Makhmali
1
+ Copyright (c) 2013 Javan Makhmali
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -16,7 +16,7 @@
16
16
  └── views <- Your views, layouts, and partials live here.
17
17
  ├── index.html.erb
18
18
  └── layout.html.erb <- Optional global layout file.
19
-
19
+
20
20
  Copy automatically maps URLs to files in your `views` directory.
21
21
 
22
22
  * `/` &rarr; `index.html.erb`
@@ -63,4 +63,4 @@ Browse to `/_copy` and drag the "Edit Copy" link to your bookmarks bar. Return t
63
63
 
64
64
  ----
65
65
 
66
- [![Build Status](http://travis-ci.org/javan/copy.png)](http://travis-ci.org/javan/copy) &mdash; &copy; 2011 Javan Makhmali
66
+ [![Build Status](http://travis-ci.org/javan/copy.png)](http://travis-ci.org/javan/copy) &mdash; &copy; 2013 Javan Makhmali
@@ -13,10 +13,10 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{Serves mostly static pages with blocks of editable copy.}
14
14
 
15
15
  s.rubyforge_project = "copy"
16
-
17
- s.add_dependency "sinatra", "~> 1.2.6"
18
- s.add_dependency "redcarpet"
19
-
16
+
17
+ s.add_dependency "sinatra", "~> 1.3.3"
18
+ s.add_dependency "redcarpet", "~> 2.2.2"
19
+
20
20
  s.add_development_dependency "mocha"
21
21
  s.add_development_dependency "rake"
22
22
  s.add_development_dependency "rack-test"
@@ -2,16 +2,16 @@ require 'sinatra/base'
2
2
  require 'erb'
3
3
  require 'redcarpet'
4
4
 
5
- module Copy
6
- class Server < Sinatra::Base
5
+ module Copy
6
+ class Server < Sinatra::Base
7
7
  set :views, './views'
8
- set :public, './public'
8
+ set :public_folder, './public'
9
9
  set :root, File.dirname(File.expand_path(__FILE__))
10
-
10
+
11
11
  helpers do
12
12
  include Rack::Utils
13
13
  alias_method :h, :escape_html
14
-
14
+
15
15
  def protected!
16
16
  unless authorized?
17
17
  response['WWW-Authenticate'] = %(Basic realm="Copy Admin Area")
@@ -24,7 +24,7 @@ module Copy
24
24
  @auth ||= Rack::Auth::Basic::Request.new(request.env)
25
25
  @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == [settings.copy_username, settings.copy_password]
26
26
  end
27
-
27
+
28
28
  def set_cache_control_header
29
29
  if settings.respond_to?(:cache_time) && settings.cache_time.is_a?(Numeric) && settings.cache_time > 0
30
30
  expires settings.cache_time, :public
@@ -32,14 +32,15 @@ module Copy
32
32
  cache_control :no_cache
33
33
  end
34
34
  end
35
-
35
+
36
36
  def format_text(name, content, options = {})
37
37
  original = content.dup
38
38
  # Apply markdown formatting.
39
- content = Redcarpet.new(content, :smart).to_html.chomp
40
-
39
+ markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
40
+ content = markdown.render(content).chomp
41
+
41
42
  html_attrs = %Q(class="_copy_editable" data-name="#{name}")
42
-
43
+
43
44
  if original =~ /\n/ # content with newlines renders in a div
44
45
  tag = options[:wrap_tag] || :div
45
46
  %Q(<#{tag} #{html_attrs}>#{content}</#{tag}>)
@@ -49,14 +50,14 @@ module Copy
49
50
  %Q(<#{tag} #{html_attrs}>#{content}</#{tag}>)
50
51
  end
51
52
  end
52
-
53
+
53
54
  def copy(name, options = {}, &block)
54
55
  if !Copy::Storage.connected? || !(content = Copy::Storage.get(name))
55
56
  # Side-step the output buffer so we can capture the block, but not output it.
56
57
  @_out_buf, old_buffer = '', @_out_buf
57
58
  content = yield
58
59
  @_out_buf = old_buffer
59
-
60
+
60
61
  # Remove newlines from the beginning
61
62
  content.gsub!(/^\n/, '')
62
63
  # Get the first line from captured text.
@@ -67,56 +68,56 @@ module Copy
67
68
  content.gsub!(Regexp.new("^#{white_space}"), '')
68
69
  # Remove all whitespace from the end, but keep the newline if present.
69
70
  content.gsub!(/\s*\z/, '') << "\n" if content =~ /\n/
70
-
71
+
71
72
  # Save the content so it can be edited.
72
73
  Copy::Storage.set(name, content) if Copy::Storage.connected?
73
74
  end
74
-
75
+
75
76
  # Append the output buffer.
76
77
  @_out_buf << format_text(name, content, options)
77
78
  end
78
-
79
+
79
80
  def partial(template)
80
81
  template_array = template.to_s.split('/')
81
82
  template = template_array[0..-2].join('/') + "/_#{template_array[-1]}.#{@_route.format}"
82
83
  send(@_route.renderer, template.to_sym, :layout => false)
83
84
  end
84
85
  end
85
-
86
+
86
87
  def self.config(&block)
87
88
  class_eval(&block)
88
89
  end
89
-
90
+
90
91
  before do
91
92
  if settings.respond_to?(:storage) && !Copy::Storage.connected?
92
93
  Copy::Storage.connect!(settings.storage)
93
94
  end
94
95
  end
95
-
96
+
96
97
  get '/_copy/?' do
97
98
  protected!
98
99
  ERB.new(File.read(settings.root + '/admin/index.html.erb')).result(self.send(:binding))
99
100
  end
100
-
101
+
101
102
  get '/_copy.js' do
102
103
  protected!
103
104
  content_type(:js)
104
105
  ERB.new(File.read(settings.root + '/admin/index.js.erb')).result(self.send(:binding))
105
106
  end
106
-
107
+
107
108
  get '/_copy/:name' do
108
109
  protected!
109
110
  @name = params[:name]
110
111
  @doc = Copy::Storage.get(params[:name])
111
112
  ERB.new(File.read(settings.root + '/admin/edit.html.erb')).result(self.send(:binding))
112
113
  end
113
-
114
+
114
115
  put '/_copy/:name' do
115
116
  protected!
116
117
  Copy::Storage.set(params[:name], params[:content])
117
118
  format_text(params[:name], Copy::Storage.get(params[:name]), :wrap_tag => params[:wrap_tag])
118
119
  end
119
-
120
+
120
121
  get '*' do
121
122
  @_route = Copy::Router.new(params[:splat].first, settings.views)
122
123
  if @_route.success?
@@ -1,3 +1,3 @@
1
1
  module Copy
2
- VERSION = '0.1.7'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -7,7 +7,7 @@ begin
7
7
  require 'turn'
8
8
  rescue LoadError
9
9
  end
10
- require 'mocha'
10
+ require 'mocha/setup'
11
11
  require 'copy'
12
12
 
13
13
  class Test::Unit::TestCase
@@ -18,7 +18,7 @@ class Test::Unit::TestCase
18
18
  def self.setup(&block)
19
19
  define_method(:setup, &block)
20
20
  end
21
-
21
+
22
22
  def self.teardown(&block)
23
23
  define_method(:teardown, &block)
24
24
  end
@@ -28,20 +28,20 @@ module CopyAppSetup
28
28
  def app
29
29
  Copy::Server
30
30
  end
31
-
31
+
32
32
  def setup
33
33
  app.config do
34
34
  set :views, File.dirname(File.expand_path(__FILE__)) + '/test_app/views'
35
35
  end
36
36
  end
37
-
37
+
38
38
  def setup_auth(user, pass)
39
39
  app.config do
40
40
  set :copy_username, user
41
41
  set :copy_password, pass
42
42
  end
43
43
  end
44
-
44
+
45
45
  def authorize!
46
46
  setup_auth 'super', 'secret'
47
47
  authorize 'super', 'secret'
metadata CHANGED
@@ -1,105 +1,104 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: copy
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 7
10
- version: 0.1.7
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Javan Makhmali
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-06-21 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2013-01-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: sinatra
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 19
30
- segments:
31
- - 1
32
- - 2
33
- - 6
34
- version: 1.2.6
20
+ - !ruby/object:Gem::Version
21
+ version: 1.3.3
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: redcarpet
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.3.3
30
+ - !ruby/object:Gem::Dependency
31
+ name: redcarpet
32
+ requirement: !ruby/object:Gem::Requirement
41
33
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.2.2
49
38
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: mocha
53
39
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.2.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: mocha
48
+ requirement: !ruby/object:Gem::Requirement
55
49
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
63
54
  type: :development
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
66
- name: rake
67
55
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
69
57
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
77
70
  type: :development
78
- version_requirements: *id004
79
- - !ruby/object:Gem::Dependency
80
- name: rack-test
81
71
  prerelease: false
82
- requirement: &id005 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
83
73
  none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rack-test
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
91
86
  type: :development
92
- version_requirements: *id005
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
93
94
  description: Serves mostly static pages with blocks of editable copy.
94
- email:
95
+ email:
95
96
  - javan@javan.us
96
- executables:
97
+ executables:
97
98
  - copy
98
99
  extensions: []
99
-
100
100
  extra_rdoc_files: []
101
-
102
- files:
101
+ files:
103
102
  - .gitignore
104
103
  - Gemfile
105
104
  - LICENSE
@@ -149,41 +148,31 @@ files:
149
148
  - test/test_app/views/with_copy_helper.html.erb
150
149
  - test/test_app/views/with_copy_helper_one_line.html.erb
151
150
  - test/test_helper.rb
152
- has_rdoc: true
153
151
  homepage: https://github.com/javan/copy
154
152
  licenses: []
155
-
156
153
  post_install_message:
157
154
  rdoc_options: []
158
-
159
- require_paths:
155
+ require_paths:
160
156
  - lib
161
- required_ruby_version: !ruby/object:Gem::Requirement
157
+ required_ruby_version: !ruby/object:Gem::Requirement
162
158
  none: false
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- hash: 3
167
- segments:
168
- - 0
169
- version: "0"
170
- required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ! '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
164
  none: false
172
- requirements:
173
- - - ">="
174
- - !ruby/object:Gem::Version
175
- hash: 3
176
- segments:
177
- - 0
178
- version: "0"
165
+ requirements:
166
+ - - ! '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
179
169
  requirements: []
180
-
181
170
  rubyforge_project: copy
182
- rubygems_version: 1.4.2
171
+ rubygems_version: 1.8.23
183
172
  signing_key:
184
173
  specification_version: 3
185
174
  summary: Simple, Sinatra-based CMS.
186
- test_files:
175
+ test_files:
187
176
  - test/router_test.rb
188
177
  - test/server_test.rb
189
178
  - test/storage_test.rb