static_content 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +118 -0
- data/app/helpers/content_helper.rb +1 -0
- data/app/models/content.rb +18 -22
- data/lib/static_content/version.rb +1 -1
- metadata +25 -8
- data/README.mkdn +0 -37
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# Static Content
|
2
|
+
[![RubyGems][gem_version_badge]][ruby_gems]
|
3
|
+
[![Travis CI][travis_ci_badge]][travis_ci]
|
4
|
+
[![Coveralls][coveralls_badge]][coveralls]
|
5
|
+
[![Code Climate][code_climate_badge]][code_climate]
|
6
|
+
[![Gemnasium][gemnasium_badge]][gemnasium]
|
7
|
+
|
8
|
+
Static Content provides an easy way of defining static content in your application.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'static_content'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install static_content
|
23
|
+
|
24
|
+
After install the gem, you just need run the install generator:
|
25
|
+
|
26
|
+
$ rails g static_content:install
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
### Creating content
|
31
|
+
|
32
|
+
The content we create can be normal text or a markdown. Let`s see the way we can create a content.
|
33
|
+
|
34
|
+
#### Standard Way
|
35
|
+
|
36
|
+
You can create as a normal model with:
|
37
|
+
|
38
|
+
Content.create({slug: :about_title, text: "My awesome about page"}, as: :admin)
|
39
|
+
|
40
|
+
special attention to the `as: :admin`, the fields is only acessible to `admin`.
|
41
|
+
|
42
|
+
This is intended to be used with admin panels such as Typus or ActiveAdmin.
|
43
|
+
|
44
|
+
#### The better way
|
45
|
+
|
46
|
+
The better way is to use the `Content.from_slug` like:
|
47
|
+
|
48
|
+
Content.from_slug(:about_title, default: "My awesome about page")
|
49
|
+
|
50
|
+
as this uses `find_or_initialize`, if is a new `slug` its create, if a old one its only return the value not raising a error.
|
51
|
+
|
52
|
+
So you can use this on a seed for example to create the default things.
|
53
|
+
|
54
|
+
### Showing content
|
55
|
+
|
56
|
+
#### content
|
57
|
+
|
58
|
+
Show your content as html converted from markdown, in your view, just add:
|
59
|
+
|
60
|
+
```
|
61
|
+
<%= c :about_title, default: "# My awesome about page" %>
|
62
|
+
```
|
63
|
+
|
64
|
+
to be converted into
|
65
|
+
|
66
|
+
```
|
67
|
+
<h1>My awesome about page</h1>
|
68
|
+
```
|
69
|
+
|
70
|
+
Please note that a `default` option is required. If it hasn't been created, it will be created upon the first request.
|
71
|
+
|
72
|
+
#### raw content
|
73
|
+
|
74
|
+
Show your raw content, in your view, just add:
|
75
|
+
|
76
|
+
```
|
77
|
+
<%= rc :about_title, default: "# My awesome about page" %>
|
78
|
+
```
|
79
|
+
|
80
|
+
no change the value as
|
81
|
+
|
82
|
+
```
|
83
|
+
# My awesome about page
|
84
|
+
```
|
85
|
+
|
86
|
+
Please note that a `default` option is required. If it hasn't been created, it will be created upon the first request.
|
87
|
+
|
88
|
+
## Warning
|
89
|
+
|
90
|
+
Static Content generates a model [`Content`](https://github.com/Helabs/static_content/blob/master/app/models/content.rb) and a table [`contents`](https://github.com/Helabs/static_content/blob/master/db/migrate/20120705141451_create_contents.rb), so your app should not contain this model and table.
|
91
|
+
|
92
|
+
## Versioning
|
93
|
+
|
94
|
+
Static Content follow the [Semantic Versioning](http://semver.org/).
|
95
|
+
|
96
|
+
## Issues
|
97
|
+
|
98
|
+
If you have problems, please create a [Github Issue](https://github.com/Helabs/static_content/issues).
|
99
|
+
|
100
|
+
## Contributing
|
101
|
+
|
102
|
+
Please see [CONTRIBUTING.md](https://github.com/Helabs/static_content/blob/master/CONTRIBUTING.md) for details.
|
103
|
+
|
104
|
+
## Credits
|
105
|
+
|
106
|
+
Static Content is maintained and funded by [HE:labs](http://helabs.com.br/opensource/).
|
107
|
+
Thank you to all the [contributors](https://github.com/Helabs/static_content/graphs/contributors).
|
108
|
+
|
109
|
+
[gem_version_badge]: https://badge.fury.io/rb/static_content.png
|
110
|
+
[ruby_gems]: http://rubygems.org/gems/static_content
|
111
|
+
[code_climate]: https://codeclimate.com/github/Helabs/static_content
|
112
|
+
[code_climate_badge]: https://codeclimate.com/github/Helabs/static_content.png
|
113
|
+
[travis_ci]: http://travis-ci.org/Helabs/static_content
|
114
|
+
[travis_ci_badge]: https://secure.travis-ci.org/Helabs/static_content.png
|
115
|
+
[gemnasium]: https://gemnasium.com/Helabs/static_content
|
116
|
+
[gemnasium_badge]: https://gemnasium.com/Helabs/static_content.png
|
117
|
+
[coveralls]: https://coveralls.io/r/Helabs/static_content
|
118
|
+
[coveralls_badge]: https://coveralls.io/repos/Helabs/static_content/badge.png?branch=master
|
data/app/models/content.rb
CHANGED
@@ -1,8 +1,21 @@
|
|
1
1
|
require 'rdiscount' #TODO: Fix this stupid require statement.
|
2
2
|
class Content < ActiveRecord::Base
|
3
|
+
|
3
4
|
attr_accessible :slug, :text, as: :admin
|
5
|
+
|
4
6
|
validates :slug, :text, presence: true
|
5
|
-
|
7
|
+
validates :slug, uniqueness: true
|
8
|
+
|
9
|
+
def self.from_slug(slug, options={})
|
10
|
+
raise ArgumentError.new("You must provide a default text for a content.") if options[:default].nil?
|
11
|
+
find_or_initialize_by_slug(slug).tap do |content|
|
12
|
+
if content.new_record?
|
13
|
+
content.name = slug
|
14
|
+
content.text = options[:default]
|
15
|
+
content.save
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
6
19
|
|
7
20
|
def parsed_text
|
8
21
|
markdown.to_html.html_safe
|
@@ -12,27 +25,10 @@ class Content < ActiveRecord::Base
|
|
12
25
|
text.html_safe
|
13
26
|
end
|
14
27
|
|
15
|
-
|
16
|
-
@content ||= RDiscount.new(text)
|
17
|
-
end
|
18
|
-
|
19
|
-
|
28
|
+
private
|
20
29
|
|
21
|
-
|
22
|
-
|
23
|
-
raise NoDefaultContentError if options[:default].nil?
|
24
|
-
find_or_initialize_by_slug(slug).tap do |content|
|
25
|
-
if content.new_record?
|
26
|
-
content.name = slug
|
27
|
-
content.text = options[:default]
|
28
|
-
content.save
|
29
|
-
end
|
30
|
-
end
|
30
|
+
def markdown
|
31
|
+
@content ||= RDiscount.new(text)
|
31
32
|
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
class NoDefaultContentError < StandardError
|
35
|
-
def initialize(msg = "You must provide a default text for a content.")
|
36
|
-
super(msg)
|
37
|
-
end
|
38
33
|
end
|
34
|
+
|
metadata
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: static_content
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Pedro Nascimento
|
9
9
|
- Sylvestre Mergulhao
|
10
10
|
- Rodrigo Pinto
|
11
|
+
- Mauro George
|
11
12
|
autorequire:
|
12
13
|
bindir: bin
|
13
14
|
cert_chain: []
|
14
|
-
date:
|
15
|
+
date: 2013-06-20 00:00:00.000000000 Z
|
15
16
|
dependencies:
|
16
17
|
- !ruby/object:Gem::Dependency
|
17
18
|
name: rails
|
@@ -36,7 +37,7 @@ dependencies:
|
|
36
37
|
requirements:
|
37
38
|
- - ~>
|
38
39
|
- !ruby/object:Gem::Version
|
39
|
-
version: 1.6
|
40
|
+
version: 2.1.6
|
40
41
|
type: :runtime
|
41
42
|
prerelease: false
|
42
43
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -44,7 +45,7 @@ dependencies:
|
|
44
45
|
requirements:
|
45
46
|
- - ~>
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.6
|
48
|
+
version: 2.1.6
|
48
49
|
- !ruby/object:Gem::Dependency
|
49
50
|
name: sqlite3
|
50
51
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,6 +62,22 @@ dependencies:
|
|
61
62
|
- - ! '>='
|
62
63
|
- !ruby/object:Gem::Version
|
63
64
|
version: '0'
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: coveralls
|
67
|
+
requirement: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
type: :development
|
74
|
+
prerelease: false
|
75
|
+
version_requirements: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
64
81
|
- !ruby/object:Gem::Dependency
|
65
82
|
name: rspec-rails
|
66
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,7 +145,7 @@ files:
|
|
128
145
|
- lib/tasks/static_content_tasks.rake
|
129
146
|
- MIT-LICENSE
|
130
147
|
- Rakefile
|
131
|
-
- README.
|
148
|
+
- README.md
|
132
149
|
homepage: https://github.com/Helabs/static_content
|
133
150
|
licenses: []
|
134
151
|
post_install_message:
|
@@ -143,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
160
|
version: '0'
|
144
161
|
segments:
|
145
162
|
- 0
|
146
|
-
hash:
|
163
|
+
hash: 2073422727724312165
|
147
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
165
|
none: false
|
149
166
|
requirements:
|
@@ -152,10 +169,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
169
|
version: '0'
|
153
170
|
segments:
|
154
171
|
- 0
|
155
|
-
hash:
|
172
|
+
hash: 2073422727724312165
|
156
173
|
requirements: []
|
157
174
|
rubyforge_project:
|
158
|
-
rubygems_version: 1.8.
|
175
|
+
rubygems_version: 1.8.25
|
159
176
|
signing_key:
|
160
177
|
specification_version: 3
|
161
178
|
summary: static_content provides a simple way of outputting static content in your
|
data/README.mkdn
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
### work in progress.
|
2
|
-
|
3
|
-
#What is static_content?
|
4
|
-
static_content provides an easy way of defining static content in your application.
|
5
|
-
|
6
|
-
## Installation
|
7
|
-
|
8
|
-
Add this line to your application's Gemfile:
|
9
|
-
|
10
|
-
gem 'static_content'
|
11
|
-
|
12
|
-
And then execute:
|
13
|
-
|
14
|
-
$ bundle
|
15
|
-
|
16
|
-
Or install it yourself as:
|
17
|
-
|
18
|
-
$ gem install static_content
|
19
|
-
|
20
|
-
After install the gem, you just need run the install generator:
|
21
|
-
|
22
|
-
$ rails g static_content:install
|
23
|
-
|
24
|
-
#Usage
|
25
|
-
|
26
|
-
In your view, just add:
|
27
|
-
|
28
|
-
```erb
|
29
|
-
<%=c :sidebar_content, default: "Placeholder Sidebar Content" %>
|
30
|
-
```
|
31
|
-
|
32
|
-
Please note that a `default` option is required. If it hasn't been created, it will be created upon the first request.
|
33
|
-
|
34
|
-
This is intended to be used with admin panels such as Typus or ActiveAdmin.
|
35
|
-
|
36
|
-
|
37
|
-
This project rocks and uses MIT-LICENSE.
|