copy 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +7 -9
- data/copy.gemspec +2 -0
- data/lib/copy/admin/copy.css +19 -14
- data/lib/copy/admin/edit.html.erb +5 -9
- data/lib/copy/admin/index.js.erb +33 -6
- data/lib/copy/version.rb +1 -1
- data/test/server_test.rb +1 -7
- metadata +32 -4
data/README.md
CHANGED
@@ -6,19 +6,17 @@
|
|
6
6
|
├── Gemfile <- Uncomment the gems you need for storage.
|
7
7
|
├── config.ru <- Configure storage, user, and password here.
|
8
8
|
├── public <- The public root of your new site.
|
9
|
-
│ ├── favicon.ico
|
9
|
+
│ ├── favicon.ico <- A blank favicon, replace with your own.
|
10
10
|
│ ├── images
|
11
11
|
│ ├── javascripts
|
12
|
-
│ │ └── main.js
|
13
|
-
│ ├── robots.txt
|
12
|
+
│ │ └── main.js <- A good place for your basic scripts.
|
13
|
+
│ ├── robots.txt <- Read file for details.
|
14
14
|
│ └── stylesheets
|
15
|
-
│ └── main.css
|
15
|
+
│ └── main.css <- Toss some CSS styles in here.
|
16
16
|
└── views <- Your views, layouts, and partials live here.
|
17
17
|
├── index.html.erb
|
18
|
-
└── layout.html.erb
|
18
|
+
└── layout.html.erb <- Optional global layout file.
|
19
19
|
|
20
|
-
The layout (`layout.html.erb`) yields to all the views. It's not required so delete it if your views contain full html documents.
|
21
|
-
|
22
20
|
Copy automatically maps URLs to files in your `views` directory.
|
23
21
|
|
24
22
|
* `/` → `index.html.erb`
|
@@ -35,7 +33,7 @@ Copy lets you define blocks of editable text in your views.
|
|
35
33
|
|
36
34
|
The text provided in the block will be saved and can then be edited live on the site. All content is formatted with Markdown. [See demo](http://copy-demo.heroku.com) for a live example or [view the source](https://github.com/javan/copy-demo).
|
37
35
|
|
38
|
-
Single line blocks will be
|
36
|
+
Single line blocks will be rendered in a span (by default). Perfect for headlines.
|
39
37
|
|
40
38
|
<h1><% copy :title do %>Like a boss!<% end %></h1>
|
41
39
|
|
@@ -65,4 +63,4 @@ Browse to `/_copy` and drag the "Edit Copy" link to your bookmarks bar. Return t
|
|
65
63
|
|
66
64
|
----
|
67
65
|
|
68
|
-
© 2011 Javan Makhmali
|
66
|
+
[](http://travis-ci.org/javan/copy) — © 2011 Javan Makhmali
|
data/copy.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_dependency "redcarpet"
|
19
19
|
|
20
20
|
s.add_development_dependency "mocha"
|
21
|
+
s.add_development_dependency "rake"
|
22
|
+
s.add_development_dependency "rack-test"
|
21
23
|
|
22
24
|
s.files = `git ls-files`.split("\n")
|
23
25
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/copy/admin/copy.css
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
}
|
20
20
|
|
21
21
|
#_copy {
|
22
|
+
font-size: 11px;
|
22
23
|
overflow: hidden;
|
23
24
|
}
|
24
25
|
|
@@ -30,32 +31,36 @@
|
|
30
31
|
font-family: monaco, menlo, monospace;
|
31
32
|
}
|
32
33
|
|
33
|
-
#_copy p
|
34
|
-
font-size: 11px;
|
34
|
+
#_copy p {
|
35
35
|
margin: 10px 0;
|
36
36
|
padding: 0;
|
37
37
|
}
|
38
38
|
|
39
|
-
#_copy p._copy_footer_left {
|
40
|
-
float: left;
|
41
|
-
}
|
42
|
-
|
43
|
-
#_copy p._copy_footer_right {
|
44
|
-
float: right;
|
45
|
-
text-align: right;
|
46
|
-
}
|
47
|
-
|
48
39
|
#_copy a._copy_cancel {
|
49
40
|
text-decoration: underline;
|
50
41
|
}
|
51
42
|
|
52
|
-
#_copy textarea
|
53
|
-
|
43
|
+
#_copy textarea {
|
44
|
+
display: none;
|
54
45
|
font-size: 13px;
|
55
46
|
width: 490px;
|
56
47
|
padding: 5px;
|
48
|
+
-webkit-transition: height 0.2s ease-out;
|
49
|
+
-moz-transition: height 0.2s ease-out;
|
50
|
+
-o-transition: height 0.2s ease-out;
|
51
|
+
transition: height 0.2s ease-out;
|
52
|
+
}
|
53
|
+
|
54
|
+
#_copy textarea._copy_small {
|
55
|
+
resize: none;
|
56
|
+
overflow: hidden;
|
57
|
+
height: 18px;
|
58
|
+
}
|
59
|
+
|
60
|
+
#_copy textarea._copy_medium {
|
61
|
+
height: 150px;
|
57
62
|
}
|
58
63
|
|
59
|
-
#_copy textarea {
|
64
|
+
#_copy textarea._copy_large {
|
60
65
|
height: 300px;
|
61
66
|
}
|
@@ -1,16 +1,12 @@
|
|
1
1
|
<div id="_copy">
|
2
2
|
<form class="_copy_edit_form" data-content-name="<%= @name %>" action="/_copy/<%= @name %>">
|
3
|
-
|
4
|
-
<
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
<p class="_copy_footer _copy_footer_left">
|
3
|
+
<p>
|
4
|
+
Format text with <a href="http://daringfireball.net/projects/markdown/syntax" target="_blank">markdown</a>.
|
5
|
+
</p>
|
6
|
+
<textarea name="content"><%=h @doc %></textarea>
|
7
|
+
<p>
|
9
8
|
<input class="_copy_submit" type="submit" value="Save" />
|
10
9
|
or <a class="_copy_cancel" href="#">cancel</a>
|
11
10
|
</p>
|
12
|
-
<p class="_copy_footer _copy_footer_right">
|
13
|
-
Format text with <a href="http://daringfireball.net/projects/markdown/syntax" target="_blank">markdown</a>.
|
14
|
-
</p>
|
15
11
|
</form>
|
16
12
|
</div>
|
data/lib/copy/admin/index.js.erb
CHANGED
@@ -15,14 +15,39 @@ jQuery.noConflict();
|
|
15
15
|
|
16
16
|
function clickable() {
|
17
17
|
$('._copy_editable').addClass('_copy_clickable');
|
18
|
+
$('._copy_clickable:empty').text('(add copy)');
|
18
19
|
}
|
19
20
|
|
20
21
|
function unclickable() {
|
21
22
|
$('._copy_editable').removeClass('_copy_clickable');
|
22
23
|
}
|
23
24
|
|
25
|
+
// Apply sizing rules (css classes) to the textarea based
|
26
|
+
// on the length of the content and presence of newlines.
|
27
|
+
function resizeTextarea() {
|
28
|
+
var textarea = $('#_copy textarea');
|
29
|
+
var content = textarea.val();
|
30
|
+
|
31
|
+
textarea.removeClass('_copy_small _copy_medium _copy_large');
|
32
|
+
|
33
|
+
if (/\n/.test(content) || content.length > 55) {
|
34
|
+
if (content.length > 300) {
|
35
|
+
textarea.addClass('_copy_large');
|
36
|
+
} else {
|
37
|
+
textarea.addClass('_copy_medium');
|
38
|
+
}
|
39
|
+
} else {
|
40
|
+
textarea.addClass('_copy_small');
|
41
|
+
}
|
42
|
+
|
43
|
+
textarea.show();
|
44
|
+
}
|
45
|
+
$('#_copy textarea').live('keydown keyup keypress change paste focus', resizeTextarea);
|
46
|
+
|
47
|
+
// Apply the styles.
|
24
48
|
$('head').append('<style><%= File.read(settings.root + '/admin/copy.css').gsub(/\n/, " \\\n") %></style>');
|
25
|
-
|
49
|
+
|
50
|
+
// When a clickable region is clicked, load the content into the editor.
|
26
51
|
$('._copy_clickable').live('click', function() {
|
27
52
|
var copy = $(this);
|
28
53
|
unclickable();
|
@@ -31,8 +56,7 @@ jQuery.noConflict();
|
|
31
56
|
success: function(html) {
|
32
57
|
$('body').prepend(html);
|
33
58
|
$('#_copy').css({ margin:'-'+($('#_copy').height() / 2)+'px 0 0 -'+($('#_copy').width() / 2)+'px' });
|
34
|
-
$('#_copy
|
35
|
-
}
|
59
|
+
$('#_copy textarea').focus(); }
|
36
60
|
});
|
37
61
|
});
|
38
62
|
|
@@ -42,12 +66,14 @@ jQuery.noConflict();
|
|
42
66
|
event.preventDefault();
|
43
67
|
});
|
44
68
|
|
45
|
-
|
69
|
+
// Hide the editor and make everything clickable if cancel is pressed.
|
70
|
+
$('._copy_cancel').live('click', function(event) {
|
71
|
+
event.preventDefault();
|
46
72
|
$('#_copy').remove();
|
47
73
|
clickable();
|
48
|
-
return false;
|
49
74
|
});
|
50
75
|
|
76
|
+
// Save the content when the submit button is pressed.
|
51
77
|
$('._copy_edit_form').live('submit', function() {
|
52
78
|
var form = $(this);
|
53
79
|
var original = $('[data-name="'+form.attr('data-content-name')+'"]');
|
@@ -55,7 +81,7 @@ jQuery.noConflict();
|
|
55
81
|
$.ajax({
|
56
82
|
type: 'PUT',
|
57
83
|
url: form.attr('action'),
|
58
|
-
data: { content: form.find('
|
84
|
+
data: { content: form.find('textarea').val(), wrap_tag: original.get(0).tagName.toLowerCase() },
|
59
85
|
success: function(html) {
|
60
86
|
$('#_copy').remove();
|
61
87
|
original.replaceWith(html);
|
@@ -64,6 +90,7 @@ jQuery.noConflict();
|
|
64
90
|
return false;
|
65
91
|
})
|
66
92
|
|
93
|
+
// Make the editable regions clickable.
|
67
94
|
clickable();
|
68
95
|
window._copy_initialized = true;
|
69
96
|
});
|
data/lib/copy/version.rb
CHANGED
data/test/server_test.rb
CHANGED
@@ -162,17 +162,11 @@ class ServerAdminTest < Test::Unit::TestCase
|
|
162
162
|
|
163
163
|
test "GET /_copy/:name" do
|
164
164
|
Copy::Storage.stubs(:connected?).returns(true)
|
165
|
-
Copy::Storage.expects(:get).with('fun').returns(
|
165
|
+
Copy::Storage.expects(:get).with('fun').returns("<b>party\n")
|
166
166
|
|
167
167
|
authorize!
|
168
168
|
get '/_copy/fun'
|
169
169
|
assert last_response.ok?, last_response.errors
|
170
|
-
# Single line content renders in a text field
|
171
|
-
assert_match 'value=""party""', last_response.body
|
172
|
-
|
173
|
-
# Multiline renders in a textarea
|
174
|
-
Copy::Storage.expects(:get).with('fun').returns("<b>party\n")
|
175
|
-
get '/_copy/fun'
|
176
170
|
assert_match "<b>party\n</textarea>", last_response.body
|
177
171
|
end
|
178
172
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: copy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Javan Makhmali
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06-
|
18
|
+
date: 2011-06-19 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -62,6 +62,34 @@ dependencies:
|
|
62
62
|
version: "0"
|
63
63
|
type: :development
|
64
64
|
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: rake
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
type: :development
|
78
|
+
version_requirements: *id004
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: rack-test
|
81
|
+
prerelease: false
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
type: :development
|
92
|
+
version_requirements: *id005
|
65
93
|
description: Serves mostly static pages with blocks of editable copy.
|
66
94
|
email:
|
67
95
|
- javan@javan.us
|