static_blocks 1.0.3 → 1.1.0
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 +40 -11
- data/app/controllers/static_blocks/snippets_controller.rb +1 -1
- data/app/models/static_blocks/snippet.rb +1 -1
- data/app/views/layouts/static_blocks/application.html.erb +11 -7
- data/app/views/static_blocks/snippets/_search.html.erb +37 -0
- data/app/views/static_blocks/snippets/index.html.erb +7 -19
- data/lib/static_blocks/engine.rb +2 -1
- data/lib/static_blocks/version.rb +1 -1
- data/lib/templates/static_blocks_config_template.rb +2 -1
- data/spec/dummy/config/initializers/static_blocks.rb +2 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/log/development.log +18370 -0
- data/spec/dummy/log/test.log +8635 -0
- data/spec/integration/translations_spec.rb +9 -0
- metadata +4 -7
- data/spec/dummy/tmp/cache/77F/2B0/snippet%3A%3Aen%3A%3Afoo +0 -1
- data/spec/dummy/tmp/cache/78E/D30/snippet%3A%3Awk%3A%3Afoo +0 -1
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# Static Blocks
|
2
2
|
|
3
|
-
Static Blocks is
|
3
|
+
Static Blocks is a light-weight CMS for Ruby on Rails.
|
4
4
|
|
5
5
|
Create snippets of content. Place them anywhere in your views.
|
6
6
|
|
7
7
|
## Features
|
8
8
|
* Simple admin interface
|
9
|
-
* i18n
|
9
|
+
* i18n multilingual support
|
10
10
|
* Optional http basic authentication
|
11
11
|
* Search
|
12
12
|
* wysihtml5 editor
|
@@ -14,19 +14,19 @@ Create snippets of content. Place them anywhere in your views.
|
|
14
14
|
|
15
15
|
## Installation
|
16
16
|
|
17
|
-
Add the following to Gemfile
|
17
|
+
Add the following to `Gemfile`:
|
18
18
|
|
19
19
|
```ruby
|
20
20
|
gem 'static_blocks'
|
21
21
|
```
|
22
22
|
|
23
|
-
Run bundle
|
23
|
+
Run bundle:
|
24
24
|
|
25
25
|
```shell
|
26
26
|
bundle install
|
27
27
|
```
|
28
28
|
|
29
|
-
Run static blocks install generator
|
29
|
+
Run static blocks install generator:
|
30
30
|
|
31
31
|
```shell
|
32
32
|
rails generate static_blocks:install
|
@@ -38,7 +38,7 @@ Run migrations:
|
|
38
38
|
rake db:migrate
|
39
39
|
```
|
40
40
|
|
41
|
-
|
41
|
+
Check that Engine has been mounted in `config/routes.rb`:
|
42
42
|
|
43
43
|
```ruby
|
44
44
|
mount StaticBlocks::Engine => "/static_blocks"
|
@@ -57,36 +57,65 @@ Use the `snippet_for` method or it's alias `s` to output a block onto any view t
|
|
57
57
|
|
58
58
|
## Configuration
|
59
59
|
|
60
|
-
|
60
|
+
During installation, a configuration file should have been created in `config/initializers/static_blocks.rb`:
|
61
61
|
|
62
62
|
```ruby
|
63
63
|
StaticBlocks.config do |config|
|
64
|
-
config.locales = ['en']
|
65
64
|
config.http_auth = false
|
66
65
|
config.username = ENV['STATIC_BLOCKS_USERNAME']
|
67
66
|
config.password = ENV['STATIC_BLOCKS_PASSWORD']
|
68
67
|
config.wysihtml5 = true
|
68
|
+
config.globalize = false
|
69
|
+
config.locales = ['en']
|
69
70
|
end
|
70
71
|
```
|
71
72
|
|
72
73
|
### i18n Internationalization
|
73
74
|
|
74
|
-
Static Blocks supports i18n internationalization.
|
75
|
+
Static Blocks supports i18n internationalization. To active, follow the steps below:
|
76
|
+
|
77
|
+
#### Step 1
|
78
|
+
|
79
|
+
Set globalize option to true.
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
config.globalize = true
|
83
|
+
```
|
84
|
+
|
85
|
+
#### Step 2
|
86
|
+
|
87
|
+
Pass in an array of locales.
|
75
88
|
|
76
89
|
```ruby
|
77
90
|
config.locales = ['en', 'wk', 'pirate']
|
78
91
|
```
|
79
92
|
|
93
|
+
#### Step 3
|
94
|
+
|
95
|
+
Skip this step if you are starting without any existing snippets. If you are enabling i18n on a site with existing snippets, you must export and import the snippets in order to copy them to the default locale.
|
96
|
+
|
80
97
|
### Optional http basic authentication
|
81
98
|
|
82
|
-
Static Blocks has an optional http basic authentication which is turned off by default. To activate, set the
|
99
|
+
Static Blocks has an optional http basic authentication which is turned off by default. To activate, set the http_auth option to true and create environment variables for the username and password.
|
83
100
|
|
84
101
|
```ruby
|
85
102
|
config.http_auth = true
|
86
103
|
```
|
87
104
|
|
105
|
+
If you are using Devise and prefer to use that instead, you could probably do something like this in `config/routes.rb`:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
authenticate :admin_user do
|
109
|
+
mount StaticBlocks::Engine => "/static_blocks"
|
110
|
+
end
|
111
|
+
```
|
112
|
+
|
88
113
|
### wysihtml5 editor
|
89
|
-
Static Blocks uses the wysihtml5 editor which is turned on by default. To deactive, set the
|
114
|
+
Static Blocks uses the wysihtml5 editor which is turned on by default. To deactive, set the wysihtml5 option to false.
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
config.wysihtml5 = false
|
118
|
+
```
|
90
119
|
|
91
120
|
## Credits
|
92
121
|
Created by Travis Luong
|
@@ -67,7 +67,7 @@ module StaticBlocks
|
|
67
67
|
# GET /static_blocks.json
|
68
68
|
def index
|
69
69
|
@search = Snippet.order('title asc').search(params[:q])
|
70
|
-
@snippets = @search.result.per_page_kaminari(params[:page]).per(10)
|
70
|
+
@snippets = @search.result(distinct: true).per_page_kaminari(params[:page]).per(10)
|
71
71
|
|
72
72
|
respond_to do |format|
|
73
73
|
format.html # index.html.erb
|
@@ -17,7 +17,9 @@
|
|
17
17
|
<li><%= link_to "List snippets", snippets_path %></li>
|
18
18
|
<li><%= link_to "New snippet", new_snippet_path %></li>
|
19
19
|
<li><%= link_to "Export snippets", export_snippets_path(:format => :csv) %></li>
|
20
|
-
|
20
|
+
<% if StaticBlocks.config.globalize %>
|
21
|
+
<li><%= link_to "Export translations", export_translations_snippets_path(:format => :csv) %></li> </ul>
|
22
|
+
<% end %>
|
21
23
|
</div><!--/.nav-collapse -->
|
22
24
|
</div>
|
23
25
|
</div>
|
@@ -34,13 +36,15 @@
|
|
34
36
|
<% end %>
|
35
37
|
<% end %>
|
36
38
|
|
37
|
-
|
38
|
-
<
|
39
|
+
<% if StaticBlocks.config.globalize %>
|
40
|
+
<div id="locale" class="well well-small">
|
41
|
+
<strong>Locale:</strong>
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
<% StaticBlocks.config.locales.each do |loc| %>
|
44
|
+
<%= link_to_unless_current loc, locale: loc %>
|
45
|
+
<% end %>
|
46
|
+
</div>
|
47
|
+
<% end %>
|
44
48
|
|
45
49
|
<%= yield %>
|
46
50
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<% if StaticBlocks.config.globalize %>
|
2
|
+
|
3
|
+
<%= search_form_for @search do |f| %>
|
4
|
+
<div class="field">
|
5
|
+
<%= f.label :title_cont, "Title contains" %>
|
6
|
+
<%= f.text_field :title_cont %>
|
7
|
+
</div>
|
8
|
+
<div class="field">
|
9
|
+
<%= f.label :translations_content_cont, "Content contains" %>
|
10
|
+
<%= f.text_field :translations_content_cont %>
|
11
|
+
</div>
|
12
|
+
<div class="field">
|
13
|
+
<%= f.label :status_cont, "Status contains" %>
|
14
|
+
<%= f.select(:status_cont, [['', ''], ['Draft', 'draft'], ['Published', 'published']]) %>
|
15
|
+
</div>
|
16
|
+
<div class="actions"><%= f.submit "Search" %></div>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<% else %>
|
20
|
+
|
21
|
+
<%= search_form_for @search do |f| %>
|
22
|
+
<div class="field">
|
23
|
+
<%= f.label :title_cont, "Title contains" %>
|
24
|
+
<%= f.text_field :title_cont %>
|
25
|
+
</div>
|
26
|
+
<div class="field">
|
27
|
+
<%= f.label :content_cont, "Content contains" %>
|
28
|
+
<%= f.text_field :content_cont %>
|
29
|
+
</div>
|
30
|
+
<div class="field">
|
31
|
+
<%= f.label :status_cont, "Status contains" %>
|
32
|
+
<%= f.select(:status_cont, [['', ''], ['Draft', 'draft'], ['Published', 'published']]) %>
|
33
|
+
</div>
|
34
|
+
<div class="actions"><%= f.submit "Search" %></div>
|
35
|
+
<% end %>
|
36
|
+
|
37
|
+
<% end %>
|
@@ -2,21 +2,7 @@
|
|
2
2
|
<div class="row">
|
3
3
|
<div class="span6">
|
4
4
|
<h2>Search</h2>
|
5
|
-
<%=
|
6
|
-
<div class="field">
|
7
|
-
<%= f.label :title_cont, "Title contains" %>
|
8
|
-
<%= f.text_field :title_cont %>
|
9
|
-
</div>
|
10
|
-
<div class="field">
|
11
|
-
<%= f.label :translations_content_cont, "Content contains" %>
|
12
|
-
<%= f.text_field :translations_content_cont %>
|
13
|
-
</div>
|
14
|
-
<div class="field">
|
15
|
-
<%= f.label :status_cont, "Status contains" %>
|
16
|
-
<%= f.select(:status_cont, [['', ''], ['Draft', 'draft'], ['Published', 'published']]) %>
|
17
|
-
</div>
|
18
|
-
<div class="actions"><%= f.submit "Search" %></div>
|
19
|
-
<% end %>
|
5
|
+
<%= render 'search' %>
|
20
6
|
</div>
|
21
7
|
<div class="span6">
|
22
8
|
<h2>Import snippets</h2>
|
@@ -24,10 +10,12 @@
|
|
24
10
|
<%= file_field_tag :file %>
|
25
11
|
<%= submit_tag "Import snippets" %>
|
26
12
|
<% end %>
|
27
|
-
|
28
|
-
|
29
|
-
<%=
|
30
|
-
|
13
|
+
<% if StaticBlocks.config.globalize %>
|
14
|
+
<h2>Import translations</h2>
|
15
|
+
<%= form_tag import_translations_snippets_path, multipart: true do %>
|
16
|
+
<%= file_field_tag :file %>
|
17
|
+
<%= submit_tag "Import translations" %>
|
18
|
+
<% end %>
|
31
19
|
<% end %>
|
32
20
|
<p class="help-block">*If you are using translations, you must import snippets first and then translations.</p>
|
33
21
|
</div>
|
data/lib/static_blocks/engine.rb
CHANGED
@@ -24,11 +24,12 @@ module StaticBlocks
|
|
24
24
|
def self.config(&block)
|
25
25
|
unless defined? @@config
|
26
26
|
@@config ||= StaticBlocks::Engine::Configuration.new
|
27
|
-
@@config.locales = ['en']
|
28
27
|
@@config.http_auth = false
|
29
28
|
@@config.username = "admin"
|
30
29
|
@@config.password = "password"
|
31
30
|
@@config.wysihtml5 = true
|
31
|
+
@@config.globalize = false
|
32
|
+
@@config.locales = ['en']
|
32
33
|
end
|
33
34
|
|
34
35
|
yield @@config if block
|
@@ -1,7 +1,8 @@
|
|
1
1
|
StaticBlocks.config do |config|
|
2
|
-
config.locales = ['en']
|
3
2
|
config.http_auth = false
|
4
3
|
config.username = ENV['STATIC_BLOCKS_USERNAME']
|
5
4
|
config.password = ENV['STATIC_BLOCKS_PASSWORD']
|
6
5
|
config.wysihtml5 = true
|
6
|
+
config.globalize = false
|
7
|
+
config.locales = ['en']
|
7
8
|
end
|
Binary file
|