static_blocks 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -7
- data/app/controllers/static_blocks/application_controller.rb +0 -4
- data/app/controllers/static_blocks/{static_blocks_controller.rb → snippets_controller.rb} +36 -36
- data/app/helpers/static_blocks/{static_blocks_helper.rb → snippets_helper.rb} +0 -0
- data/app/models/static_blocks/{static_block.rb → snippet.rb} +19 -19
- data/app/views/layouts/static_blocks/application.html.erb +10 -8
- data/app/views/static_blocks/{static_blocks → snippets}/_form.html.erb +4 -4
- data/app/views/static_blocks/snippets/edit.html.erb +4 -0
- data/app/views/static_blocks/{static_blocks → snippets}/index.html.erb +14 -14
- data/app/views/static_blocks/snippets/new.html.erb +3 -0
- data/app/views/static_blocks/snippets/show.html.erb +23 -0
- data/config/routes.rb +11 -7
- data/db/migrate/20130611042319_create_static_blocks_static_blocks.rb +2 -2
- data/db/migrate/20130612034816_create_static_block_translations.rb +3 -3
- data/lib/static_blocks/engine.rb +2 -1
- data/lib/static_blocks/helpers.rb +11 -11
- data/lib/static_blocks/version.rb +1 -1
- data/lib/tasks/populate.rake +1 -1
- data/spec/dummy/app/views/info/index.html.erb +1 -1
- data/spec/dummy/config/initializers/static_blocks.rb +2 -1
- data/spec/dummy/config/routes.rb +1 -2
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20130611042521_create_static_blocks_static_blocks.static_blocks.rb +2 -2
- data/spec/dummy/db/migrate/20130612035223_create_static_block_translations.static_blocks.rb +3 -3
- data/spec/dummy/db/schema.rb +5 -5
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +34145 -0
- data/spec/dummy/log/test.log +17664 -0
- data/spec/dummy/tmp/capybara/capybara-201306271715434400421805.html +105 -0
- data/spec/dummy/tmp/capybara/capybara-201306271720151310204564.html +2 -0
- data/spec/dummy/tmp/capybara/capybara-201306271721083468243101.html +2 -0
- data/spec/dummy/tmp/capybara/capybara-201306271721478445036540.html +2 -0
- data/spec/dummy/tmp/capybara/capybara-201306271721487345133836.html +97 -0
- data/spec/dummy/tmp/capybara/capybara-201306271722466837246437.html +2 -0
- data/spec/dummy/tmp/capybara/capybara-201306271722471821301599.html +105 -0
- data/spec/dummy/tmp/capybara/capybara-201306271724391294417961.html +2 -0
- data/spec/dummy/tmp/capybara/capybara-201306271725269568506755.html +2 -0
- data/spec/dummy/tmp/capybara/capybara-201306271725532116510731.html +2 -0
- data/spec/dummy/tmp/capybara/capybara-201306271726399551759972.html +97 -0
- data/spec/dummy/tmp/capybara/capybara-201306271732329832575014.html +105 -0
- data/spec/dummy/tmp/capybara/capybara-201306271733118671160246.html +105 -0
- data/spec/dummy/tmp/capybara/capybara-201306271733551813912702.html +105 -0
- data/spec/dummy/tmp/capybara/capybara-201306271736422992487098.html +105 -0
- data/spec/dummy/tmp/capybara/capybara-201306271737422569974960.html +2 -0
- data/spec/dummy/tmp/capybara/capybara-201306271741158405455507.html +3 -0
- data/spec/dummy/tmp/pids/server.pid +1 -0
- data/spec/helpers/static_blocks_helper_spec.rb +4 -4
- data/spec/integration/import_export_spec.rb +41 -0
- data/spec/integration/search_spec.rb +41 -0
- data/spec/integration/static_blocks_spec.rb +12 -12
- data/spec/integration/translations_spec.rb +24 -0
- data/spec/models/static_block_spec.rb +3 -3
- metadata +52 -14
- data/app/views/static_blocks/static_blocks/edit.html.erb +0 -4
- data/app/views/static_blocks/static_blocks/new.html.erb +0 -3
- data/app/views/static_blocks/static_blocks/show.html.erb +0 -23
- data/spec/dummy/tmp/cache/96E/880/static_block%3A%3Aen%3A%3Afoo +0 -2
- data/spec/dummy/tmp/cache/97D/300/static_block%3A%3Awk%3A%3Afoo +0 -2
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Static Blocks
|
2
2
|
|
3
|
-
Static Blocks is an ultra light-weight CMS for Ruby on Rails.
|
3
|
+
Static Blocks is an ultra light-weight CMS for Ruby on Rails.
|
4
|
+
|
5
|
+
Create snippets of content. Place them anywhere in your views.
|
4
6
|
|
5
7
|
## Features
|
6
8
|
* Simple admin interface
|
@@ -39,17 +41,17 @@ rake db:migrate
|
|
39
41
|
Mount engine in routes.rb:
|
40
42
|
|
41
43
|
```ruby
|
42
|
-
mount StaticBlocks::Engine => "/
|
44
|
+
mount StaticBlocks::Engine => "/static_blocks"
|
43
45
|
```
|
44
46
|
|
45
47
|
## Usage
|
46
48
|
|
47
|
-
Visit `/
|
49
|
+
Visit `/static_blocks` and create some static blocks.
|
48
50
|
|
49
|
-
Use the `
|
51
|
+
Use the `snippet_for` method or it's alias `s` to output a block onto any view template. Pass in the title of the static block as argument. Use `raw` if you do not want to escape the html.
|
50
52
|
|
51
53
|
```
|
52
|
-
<%=raw
|
54
|
+
<%=raw snippet_for('foo') %>
|
53
55
|
<%=raw s('foo') %>
|
54
56
|
```
|
55
57
|
|
@@ -63,6 +65,7 @@ StaticBlocks.config do |config|
|
|
63
65
|
config.http_auth = false
|
64
66
|
config.username = ENV['STATIC_BLOCKS_USERNAME']
|
65
67
|
config.password = ENV['STATIC_BLOCKS_PASSWORD']
|
68
|
+
config.wysihtml5 = true
|
66
69
|
end
|
67
70
|
```
|
68
71
|
|
@@ -71,7 +74,7 @@ end
|
|
71
74
|
Static Blocks supports i18n internationalization. Pass in an array of locales to it's config option:
|
72
75
|
|
73
76
|
```ruby
|
74
|
-
config.locales = ['en', 'wk', '
|
77
|
+
config.locales = ['en', 'wk', 'pirate']
|
75
78
|
```
|
76
79
|
|
77
80
|
### Optional http basic authentication
|
@@ -82,8 +85,11 @@ Static Blocks has an optional http basic authentication which is turned off by d
|
|
82
85
|
config.http_auth = true
|
83
86
|
```
|
84
87
|
|
88
|
+
### wysihtml5 editor
|
89
|
+
Static Blocks uses the wysihtml5 editor which is turned on by default. To deactive, set the config option to false.
|
90
|
+
|
85
91
|
## Credits
|
86
|
-
|
92
|
+
Created by Travis Luong
|
87
93
|
|
88
94
|
## License
|
89
95
|
[MIT](http://opensource.org/licenses/MIT)
|
@@ -11,10 +11,6 @@ module StaticBlocks
|
|
11
11
|
|
12
12
|
def set_locale
|
13
13
|
I18n.locale = params[:locale] if params[:locale].present?
|
14
|
-
# current_user.locale
|
15
|
-
# request.subdomain
|
16
|
-
# request.env["HTTP_ACCEPT_LANGUAGE"]
|
17
|
-
# request.remote_ip
|
18
14
|
end
|
19
15
|
|
20
16
|
def default_url_options(options = {})
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require_dependency "static_blocks/application_controller"
|
2
2
|
|
3
3
|
module StaticBlocks
|
4
|
-
class
|
4
|
+
class SnippetsController < ApplicationController
|
5
5
|
|
6
6
|
def export
|
7
7
|
t = Time.now.strftime('%Y%m%d%H%M%S')
|
8
8
|
filename = "static-blocks-#{t}.csv"
|
9
9
|
respond_to do |format|
|
10
10
|
format.csv do
|
11
|
-
send_data
|
11
|
+
send_data Snippet.to_csv, :filename => filename
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -18,7 +18,7 @@ module StaticBlocks
|
|
18
18
|
filename = "static-blocks-translations-#{t}.csv"
|
19
19
|
respond_to do |format|
|
20
20
|
format.csv do
|
21
|
-
send_data
|
21
|
+
send_data Snippet.translations_to_csv, :filename => filename
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -31,7 +31,7 @@ module StaticBlocks
|
|
31
31
|
redirect_to root_url
|
32
32
|
flash[:error] = "Wrong file. You uploaded the translations."
|
33
33
|
else
|
34
|
-
|
34
|
+
Snippet.import(params[:file])
|
35
35
|
redirect_to root_url, notice: "Static Blocks imported"
|
36
36
|
end
|
37
37
|
end
|
@@ -41,7 +41,7 @@ module StaticBlocks
|
|
41
41
|
redirect_to root_url
|
42
42
|
flash[:error] = "You did not attach a file."
|
43
43
|
elsif params[:file].original_filename.include? 'translations'
|
44
|
-
|
44
|
+
Snippet.import_translations(params[:file])
|
45
45
|
redirect_to root_url, notice: "Static Block translations imported"
|
46
46
|
else
|
47
47
|
redirect_to root_url
|
@@ -52,82 +52,82 @@ module StaticBlocks
|
|
52
52
|
# GET /static_blocks
|
53
53
|
# GET /static_blocks.json
|
54
54
|
def index
|
55
|
-
@search =
|
56
|
-
@
|
55
|
+
@search = Snippet.order('title asc').search(params[:q])
|
56
|
+
@snippets = @search.result.per_page_kaminari(params[:page]).per(10)
|
57
57
|
|
58
58
|
respond_to do |format|
|
59
59
|
format.html # index.html.erb
|
60
|
-
format.json { render json: @
|
60
|
+
format.json { render json: @snippets }
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
# GET /
|
65
|
-
# GET /
|
64
|
+
# GET /snippets/1
|
65
|
+
# GET /snippets/1.json
|
66
66
|
def show
|
67
|
-
@
|
67
|
+
@snippet = Snippet.find(params[:id])
|
68
68
|
|
69
69
|
respond_to do |format|
|
70
70
|
format.html # show.html.erb
|
71
|
-
format.json { render json: @
|
71
|
+
format.json { render json: @snippet }
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
# GET /
|
76
|
-
# GET /
|
75
|
+
# GET /snippets/new
|
76
|
+
# GET /snippets/new.json
|
77
77
|
def new
|
78
|
-
@
|
78
|
+
@snippet = Snippet.new
|
79
79
|
|
80
80
|
respond_to do |format|
|
81
81
|
format.html # new.html.erb
|
82
|
-
format.json { render json: @
|
82
|
+
format.json { render json: @snippet }
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
# GET /
|
86
|
+
# GET /snippets/1/edit
|
87
87
|
def edit
|
88
|
-
@
|
88
|
+
@snippet = Snippet.find(params[:id])
|
89
89
|
end
|
90
90
|
|
91
|
-
# POST /
|
92
|
-
# POST /
|
91
|
+
# POST /snippets
|
92
|
+
# POST /snippets.json
|
93
93
|
def create
|
94
|
-
@
|
94
|
+
@snippet = Snippet.new(params[:snippet])
|
95
95
|
|
96
96
|
respond_to do |format|
|
97
|
-
if @
|
98
|
-
format.html { redirect_to @
|
99
|
-
format.json { render json: @
|
97
|
+
if @snippet.save
|
98
|
+
format.html { redirect_to @snippet, notice: 'Snippet was successfully created.' }
|
99
|
+
format.json { render json: @snippet, status: :created, location: @snippet }
|
100
100
|
else
|
101
101
|
format.html { render action: "new" }
|
102
|
-
format.json { render json: @
|
102
|
+
format.json { render json: @snippet.errors, status: :unprocessable_entity }
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
# PUT /
|
108
|
-
# PUT /
|
107
|
+
# PUT /snippets/1
|
108
|
+
# PUT /snippets/1.json
|
109
109
|
def update
|
110
|
-
@
|
110
|
+
@snippet = Snippet.find(params[:id])
|
111
111
|
|
112
112
|
respond_to do |format|
|
113
|
-
if @
|
114
|
-
format.html { redirect_to @
|
113
|
+
if @snippet.update_attributes(params[:snippet])
|
114
|
+
format.html { redirect_to @snippet, notice: 'Static block was successfully updated.' }
|
115
115
|
format.json { head :no_content }
|
116
116
|
else
|
117
117
|
format.html { render action: "edit" }
|
118
|
-
format.json { render json: @
|
118
|
+
format.json { render json: @snippet.errors, status: :unprocessable_entity }
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
|
-
# DELETE /
|
124
|
-
# DELETE /
|
123
|
+
# DELETE /snippets/1
|
124
|
+
# DELETE /snippets/1.json
|
125
125
|
def destroy
|
126
|
-
@
|
127
|
-
@
|
126
|
+
@snippet = Snippet.find(params[:id])
|
127
|
+
@snippet.destroy
|
128
128
|
|
129
129
|
respond_to do |format|
|
130
|
-
format.html { redirect_to
|
130
|
+
format.html { redirect_to snippets_url }
|
131
131
|
format.json { head :no_content }
|
132
132
|
end
|
133
133
|
end
|
File without changes
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module StaticBlocks
|
2
|
-
class
|
2
|
+
class Snippet < ActiveRecord::Base
|
3
3
|
attr_accessible :content, :status, :title
|
4
4
|
after_save :clear_cache
|
5
5
|
scope :published, where(:status => 'published')
|
@@ -11,22 +11,22 @@ module StaticBlocks
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def clear_cache
|
14
|
-
Rails.cache.delete("
|
14
|
+
Rails.cache.delete("snippet::"+I18n.locale.to_s+"::"+title)
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.to_csv(options = {})
|
18
|
-
|
19
|
-
|
18
|
+
snippets = self.connection.select_all('select * from static_blocks_snippets')
|
19
|
+
snippets_column_names = snippets.first.keys
|
20
20
|
CSV.generate(options) do |csv|
|
21
|
-
csv <<
|
22
|
-
|
23
|
-
csv << s.values_at(*
|
21
|
+
csv << snippets_column_names
|
22
|
+
snippets.each do |s|
|
23
|
+
csv << s.values_at(*snippets_column_names)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def self.translations_to_csv(options = {})
|
29
|
-
translations = self.connection.select_all('select * from
|
29
|
+
translations = self.connection.select_all('select * from static_blocks_snippet_translations')
|
30
30
|
translation_column_names = translations.first.keys
|
31
31
|
CSV.generate(options) do |csv|
|
32
32
|
csv << translation_column_names
|
@@ -38,30 +38,30 @@ module StaticBlocks
|
|
38
38
|
|
39
39
|
def self.import(file)
|
40
40
|
CSV.foreach(file.path, headers: true) do |row|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
snippet = find_by_title(row["title"]) || new
|
42
|
+
snippet.attributes = row.to_hash.slice(*accessible_attributes)
|
43
|
+
snippet.id = row['id']
|
44
|
+
snippet.save!
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
def self.import_translations(file)
|
49
49
|
CSV.foreach(file.path, headers: true) do |row|
|
50
50
|
# find translation
|
51
|
-
raw_sql = "SELECT * FROM
|
51
|
+
raw_sql = "SELECT * FROM static_blocks_snippet_translations WHERE id=#{row['id']}"
|
52
52
|
translation = ActiveRecord::Base.connection.execute(raw_sql)
|
53
53
|
if translation.present?
|
54
54
|
# update existing translation
|
55
55
|
raw_sql = "
|
56
|
-
UPDATE
|
57
|
-
SET
|
58
|
-
WHERE id=%d" % [row['
|
56
|
+
UPDATE static_blocks_snippet_translations
|
57
|
+
SET static_blocks_snippet_id=%d, locale='%s', content='%s', created_at='%s', updated_at='%s'
|
58
|
+
WHERE id=%d" % [row['static_blocks_snippet_id'], row['locale'], row['content'], row['created_at'], row['updated_at'], row['id']]
|
59
59
|
else
|
60
60
|
# create new translation
|
61
61
|
raw_sql = "
|
62
|
-
INSERT INTO
|
63
|
-
('id', '
|
64
|
-
('%d', '%d', '%s', '%s', '%s', '%s')" % [row['id'], row['
|
62
|
+
INSERT INTO static_blocks_snippet_translations
|
63
|
+
('id', 'static_blocks_snippet_id', 'locale', 'content', 'created_at', 'updated_at') VALUES
|
64
|
+
('%d', '%d', '%s', '%s', '%s', '%s')" % [row['id'], row['static_blocks_snippet_id'], row['locale'], row['content'], row['created_at'], row['updated_at']]
|
65
65
|
end
|
66
66
|
ActiveRecord::Base.connection.execute(raw_sql)
|
67
67
|
end
|
@@ -11,13 +11,13 @@
|
|
11
11
|
<div class="navbar">
|
12
12
|
<div class="navbar-inner">
|
13
13
|
<div class="container">
|
14
|
-
<%= link_to "Static Blocks",
|
14
|
+
<%= link_to "Static Blocks", snippets_path, :class => "brand" %>
|
15
15
|
<div class="nav-collapse collapse">
|
16
16
|
<ul class="nav pull-right">
|
17
|
-
<li><%= link_to "List blocks",
|
18
|
-
<li><%= link_to "New block",
|
19
|
-
<li><%= link_to "Export",
|
20
|
-
<li><%= link_to "Export translations",
|
17
|
+
<li><%= link_to "List blocks", snippets_path %></li>
|
18
|
+
<li><%= link_to "New block", new_snippet_path %></li>
|
19
|
+
<li><%= link_to "Export", export_snippets_path(:format => :csv) %></li>
|
20
|
+
<li><%= link_to "Export translations", export_translations_snippets_path(:format => :csv) %></li> </ul>
|
21
21
|
</div><!--/.nav-collapse -->
|
22
22
|
</div>
|
23
23
|
</div>
|
@@ -34,11 +34,11 @@
|
|
34
34
|
<% end %>
|
35
35
|
<% end %>
|
36
36
|
|
37
|
-
<div id="locale">
|
38
|
-
Language
|
37
|
+
<div id="locale" class="well well-small">
|
38
|
+
<strong>Language:</strong>
|
39
39
|
|
40
40
|
<% StaticBlocks.config.locales.each do |loc| %>
|
41
|
-
|
41
|
+
<%= link_to_unless_current loc, locale: loc %>
|
42
42
|
<% end %>
|
43
43
|
</div>
|
44
44
|
|
@@ -46,6 +46,7 @@
|
|
46
46
|
|
47
47
|
</div>
|
48
48
|
|
49
|
+
<% if StaticBlocks.config.wysihtml5 %>
|
49
50
|
<script type="text/javascript">
|
50
51
|
$('.wysihtml5').each(function(i, elem) {
|
51
52
|
$(elem).wysihtml5({
|
@@ -53,6 +54,7 @@
|
|
53
54
|
});
|
54
55
|
});
|
55
56
|
</script>
|
57
|
+
<% end %>
|
56
58
|
|
57
59
|
</body>
|
58
60
|
</html>
|
@@ -1,10 +1,10 @@
|
|
1
|
-
<%= form_for(@
|
2
|
-
<% if @
|
1
|
+
<%= form_for(@snippet) do |f| %>
|
2
|
+
<% if @snippet.errors.any? %>
|
3
3
|
<div id="error_explanation">
|
4
|
-
<h2><%= pluralize(@
|
4
|
+
<h2><%= pluralize(@snippet.errors.count, "error") %> prohibited this snippet from being saved:</h2>
|
5
5
|
|
6
6
|
<ul>
|
7
|
-
<% @
|
7
|
+
<% @snippet.errors.full_messages.each do |msg| %>
|
8
8
|
<li><%= msg %></li>
|
9
9
|
<% end %>
|
10
10
|
</ul>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<h1>Listing
|
1
|
+
<h1>Listing snippets</h1>
|
2
2
|
<div class="row">
|
3
3
|
<div class="span6">
|
4
4
|
<h2>Search</h2>
|
@@ -8,8 +8,8 @@
|
|
8
8
|
<%= f.text_field :title_cont %>
|
9
9
|
</div>
|
10
10
|
<div class="field">
|
11
|
-
<%= f.label :
|
12
|
-
<%= f.text_field :
|
11
|
+
<%= f.label :translations_content_cont, "Content contains" %>
|
12
|
+
<%= f.text_field :translations_content_cont %>
|
13
13
|
</div>
|
14
14
|
<div class="field">
|
15
15
|
<%= f.label :status_cont, "Status contains" %>
|
@@ -20,19 +20,19 @@
|
|
20
20
|
</div>
|
21
21
|
<div class="span6">
|
22
22
|
<h2>Import</h2>
|
23
|
-
<%= form_tag
|
23
|
+
<%= form_tag import_snippets_path, multipart: true do %>
|
24
24
|
<%= file_field_tag :file %>
|
25
25
|
<%= submit_tag "Import" %>
|
26
26
|
<% end %>
|
27
27
|
<h2>Import Translations</h2>
|
28
|
-
<%= form_tag
|
28
|
+
<%= form_tag import_translations_snippets_path, multipart: true do %>
|
29
29
|
<%= file_field_tag :file %>
|
30
30
|
<%= submit_tag "Import Translations" %>
|
31
31
|
<% end %>
|
32
32
|
</div>
|
33
33
|
</div>
|
34
34
|
|
35
|
-
<%= paginate @
|
35
|
+
<%= paginate @snippets, :theme => 'twitter-bootstrap' %>
|
36
36
|
|
37
37
|
<table id="static-block-list" class="table table-striped">
|
38
38
|
<tr>
|
@@ -44,16 +44,16 @@
|
|
44
44
|
<th></th>
|
45
45
|
</tr>
|
46
46
|
|
47
|
-
<% @
|
47
|
+
<% @snippets.each do |snippet| %>
|
48
48
|
<tr>
|
49
|
-
<td><%=
|
50
|
-
<td><%=
|
51
|
-
<td><%=
|
52
|
-
<td><%= link_to 'Show',
|
53
|
-
<td><%= link_to 'Edit',
|
54
|
-
<td><%= link_to 'Destroy',
|
49
|
+
<td><%= snippet.title %></td>
|
50
|
+
<td><%= snippet.content %></td>
|
51
|
+
<td><%= snippet.status %></td>
|
52
|
+
<td><%= link_to 'Show', snippet_path(snippet), class: "btn btn-mini btn-success" %></td>
|
53
|
+
<td><%= link_to 'Edit', edit_snippet_path(snippet), class: "btn btn-mini btn-warning" %></td>
|
54
|
+
<td><%= link_to 'Destroy', snippet, class: "btn btn-mini btn-danger", method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
55
55
|
</tr>
|
56
56
|
<% end %>
|
57
57
|
</table>
|
58
58
|
|
59
|
-
<%= paginate @
|
59
|
+
<%= paginate @snippets, :theme => 'twitter-bootstrap' %>
|