activeadmin_cms 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG +3 -0
- data/app/services/activeadmin_cms/composer_service.rb +44 -0
- data/app/services/activeadmin_cms/menu_builder_service.rb +12 -0
- data/app/services/activeadmin_cms/pages_service.rb +13 -0
- data/app/services/activeadmin_cms/processors/base.rb +17 -0
- data/app/services/activeadmin_cms/processors/parse_menu.rb +25 -0
- data/app/services/activeadmin_cms/processors/parse_template.rb +9 -0
- data/lib/activeadmin_cms/engine.rb +1 -0
- data/lib/activeadmin_cms/version.rb +1 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +55 -0
- metadata +20 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
M2QxNWQzOTJmMjc5NzhmZWU1YThkNDhiODYyYjUzNDBlZGIyYzViMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDQxZTRiNjRhNmQ4MGYwMzNjOGRjYTExMmFiMTdjYzAyMjdmOTE0Zg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzkzOWUwNTg0NmRlYWE2ZmU5ZjJiYzM5NTVlYWQ4MTdhMWU5YjNmYjkyYTZk
|
10
|
+
MTI1MjQ2NjcwY2QzYWU3MjliNmE0MjMxN2ViNWFjYzdjNjIxNzU5N2U0YzBj
|
11
|
+
NWQzNmI2OWNlYTkzZWRmYzZhODQxYTA3OGQwNGFmODBhMGUwNDU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTNkM2JlM2E0YTIwYmRlZGRkMjljZDhmNDRjMDExMjVhNWYwODZmN2Q4MGFl
|
14
|
+
MTM5Mjg2ZWM1MGQ3MGVlMjk3MTFlZGQxMGVkNTY3ZDM2NzdiMDk2MTExYmRj
|
15
|
+
YTViNTU3MGNhYmRkYTc1ZDBhMTljMGZhNzZjOGE2Y2VlMWUwNTk=
|
data/CHANGELOG
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
module ActiveadminCms
|
2
|
+
class ComposerService < Cyrax::Base
|
3
|
+
class << self
|
4
|
+
def render(html, &block)
|
5
|
+
self.new(html).render(&block)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(html = nil)
|
10
|
+
@html = html
|
11
|
+
@options = {}
|
12
|
+
@processors = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def render(&block)
|
16
|
+
block.call(self) if block_given?
|
17
|
+
render!
|
18
|
+
end
|
19
|
+
|
20
|
+
def render!
|
21
|
+
processor_classes.each do |processor_class|
|
22
|
+
@html = processor_class.new(@html, @options).process!
|
23
|
+
end
|
24
|
+
@html
|
25
|
+
end
|
26
|
+
|
27
|
+
def process_with(processor)
|
28
|
+
@processors << processor
|
29
|
+
end
|
30
|
+
alias_method :process, :process_with
|
31
|
+
|
32
|
+
def assign(option, value)
|
33
|
+
@options[option.to_sym] = value
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def processor_classes
|
39
|
+
@processors.map do |processor|
|
40
|
+
"ActiveadminCms::Processors::#{processor.to_s.camelize}".constantize
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ActiveadminCms
|
2
|
+
class MenuBuilderService
|
3
|
+
def initialize
|
4
|
+
ActiveadminCms::Engine.config.page_categories.each do |category|
|
5
|
+
self.define_singleton_method :"#{category}_pages" do
|
6
|
+
ActiveadminCms::Page.where(category: category)
|
7
|
+
end
|
8
|
+
self.class.liquid_methods :"#{category}_pages"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -19,6 +19,19 @@ module ActiveadminCms
|
|
19
19
|
def find_by_slug(slug)
|
20
20
|
ActiveadminCms::Page.find_by_slug(slug)
|
21
21
|
end
|
22
|
+
|
23
|
+
def menu_builder
|
24
|
+
ActiveadminCms::MenuBuilderService.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def render(page)
|
28
|
+
ActiveadminCms::ComposerService.render page.content do |service|
|
29
|
+
service.assign :page, page
|
30
|
+
service.assign :menu, menu_builder
|
31
|
+
service.process_with :parse_menu
|
32
|
+
service.process_with :parse_template
|
33
|
+
end
|
34
|
+
end
|
22
35
|
end
|
23
36
|
end
|
24
37
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class ActiveadminCms::Processors::ParseMenu < ActiveadminCms::Processors::Base
|
2
|
+
def process
|
3
|
+
@html.scan(menu_regexp).each do |data|
|
4
|
+
html_original = data[0]
|
5
|
+
html_processed = wrap(data[2], data[1])
|
6
|
+
html_processed.gsub!(/\{\{([a-z]\s)?(?!#{stop_tags})([^\%\/]*?)\}\}/) { "{{menu_item.#{$2}}}" }
|
7
|
+
@html.gsub!(html_original, html_processed)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def menu_regexp
|
13
|
+
/(\{\{\s*menu\s*\:([a-z]*)\s*\}\}(.*?)\{\{\s*\/\s?menu\s*\}\})/m
|
14
|
+
end
|
15
|
+
|
16
|
+
def wrap(content, category)
|
17
|
+
content.prepend "{% for menu_item in menu.#{category}_pages %}"
|
18
|
+
content.concat "{% endfor %}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def stop_tags
|
22
|
+
/\s*menu_item\s*|\s*menu\s*\:[a-z]*/
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|
data/test/dummy/log/test.log
CHANGED
@@ -748,3 +748,58 @@ ActiveadminCmsTest: test_truth
|
|
748
748
|
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
749
749
|
[1m[35m (0.0ms)[0m ROLLBACK TO SAVEPOINT active_record_1
|
750
750
|
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
751
|
+
[1m[36m (1.2ms)[0m [1mDELETE FROM "activeadmin_cms_posts";[0m
|
752
|
+
[1m[35m (0.1ms)[0m SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
|
753
|
+
[1m[36m (0.1ms)[0m [1mDELETE FROM sqlite_sequence where name = 'activeadmin_cms_posts';[0m
|
754
|
+
[1m[35m (1.0ms)[0m DELETE FROM "activeadmin_cms_pages";
|
755
|
+
[1m[36m (0.1ms)[0m [1mSELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';[0m
|
756
|
+
[1m[35m (0.1ms)[0m DELETE FROM sqlite_sequence where name = 'activeadmin_cms_pages';
|
757
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
758
|
+
-----------------------------------------------------
|
759
|
+
#publish: test_0001_should change status to published
|
760
|
+
-----------------------------------------------------
|
761
|
+
[1m[35m (0.0ms)[0m SAVEPOINT active_record_1
|
762
|
+
[1m[36m (0.0ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
763
|
+
[1m[35m (0.0ms)[0m SAVEPOINT active_record_1
|
764
|
+
[1m[36mSQL (25.8ms)[0m [1mINSERT INTO "activeadmin_cms_posts" ("content", "created_at", "title", "updated_at") VALUES (?, ?, ?, ?)[0m [["content", "Foo content"], ["created_at", Sun, 20 Oct 2013 21:42:16 UTC +00:00], ["title", "Foo post"], ["updated_at", Sun, 20 Oct 2013 21:42:16 UTC +00:00]]
|
765
|
+
[1m[35mSQL (0.2ms)[0m UPDATE "activeadmin_cms_posts" SET "published" = ?, "updated_at" = ? WHERE "activeadmin_cms_posts"."id" = 1 [["published", true], ["updated_at", Sun, 20 Oct 2013 21:42:16 UTC +00:00]]
|
766
|
+
[1m[36mActiveadminCms::Post Load (0.1ms)[0m [1mSELECT "activeadmin_cms_posts".* FROM "activeadmin_cms_posts" WHERE "activeadmin_cms_posts"."id" = ? LIMIT 1[0m [["id", 1]]
|
767
|
+
[1m[35m (0.1ms)[0m ROLLBACK TO SAVEPOINT active_record_1
|
768
|
+
[1m[36m (0.4ms)[0m [1mrollback transaction[0m
|
769
|
+
[1m[35m (0.0ms)[0m begin transaction
|
770
|
+
-----------------------------------------------------
|
771
|
+
#publish: test_0001_should change status to published
|
772
|
+
-----------------------------------------------------
|
773
|
+
[1m[36m (0.1ms)[0m [1mSAVEPOINT active_record_1[0m
|
774
|
+
[1m[35m (0.0ms)[0m RELEASE SAVEPOINT active_record_1
|
775
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
776
|
+
[1m[35mActiveadminCms::Page Exists (0.1ms)[0m SELECT 1 AS one FROM "activeadmin_cms_pages" WHERE "activeadmin_cms_pages"."slug" = 'slug-1' LIMIT 1
|
777
|
+
[1m[36mSQL (0.5ms)[0m [1mINSERT INTO "activeadmin_cms_pages" ("content", "created_at", "slug", "title", "updated_at") VALUES (?, ?, ?, ?, ?)[0m [["content", "Foo content"], ["created_at", Sun, 20 Oct 2013 21:42:16 UTC +00:00], ["slug", "slug-1"], ["title", "Foo page"], ["updated_at", Sun, 20 Oct 2013 21:42:16 UTC +00:00]]
|
778
|
+
[1m[35mActiveadminCms::Page Exists (0.1ms)[0m SELECT 1 AS one FROM "activeadmin_cms_pages" WHERE ("activeadmin_cms_pages"."slug" = 'slug-1' AND "activeadmin_cms_pages"."id" != 1) LIMIT 1
|
779
|
+
[1m[36mSQL (0.2ms)[0m [1mUPDATE "activeadmin_cms_pages" SET "content" = ?, "published" = ?, "updated_at" = ? WHERE "activeadmin_cms_pages"."id" = 1[0m [["content", nil], ["published", true], ["updated_at", Sun, 20 Oct 2013 21:42:16 UTC +00:00]]
|
780
|
+
[1m[35mActiveadminCms::Page Load (0.1ms)[0m SELECT "activeadmin_cms_pages".* FROM "activeadmin_cms_pages" WHERE "activeadmin_cms_pages"."id" = ? LIMIT 1 [["id", 1]]
|
781
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK TO SAVEPOINT active_record_1[0m
|
782
|
+
[1m[35m (0.5ms)[0m rollback transaction
|
783
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
784
|
+
--------------------------------------------------
|
785
|
+
#publish: test_0002_should move content from draft
|
786
|
+
--------------------------------------------------
|
787
|
+
[1m[35m (0.0ms)[0m SAVEPOINT active_record_1
|
788
|
+
[1m[36m (0.0ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
789
|
+
[1m[35m (0.0ms)[0m SAVEPOINT active_record_1
|
790
|
+
[1m[36mActiveadminCms::Page Exists (0.1ms)[0m [1mSELECT 1 AS one FROM "activeadmin_cms_pages" WHERE "activeadmin_cms_pages"."slug" = 'slug-2' LIMIT 1[0m
|
791
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "activeadmin_cms_pages" ("content", "created_at", "slug", "title", "updated_at") VALUES (?, ?, ?, ?, ?) [["content", "Foo content"], ["created_at", Sun, 20 Oct 2013 21:42:16 UTC +00:00], ["slug", "slug-2"], ["title", "Foo page"], ["updated_at", Sun, 20 Oct 2013 21:42:16 UTC +00:00]]
|
792
|
+
[1m[36mActiveadminCms::Page Exists (0.1ms)[0m [1mSELECT 1 AS one FROM "activeadmin_cms_pages" WHERE ("activeadmin_cms_pages"."slug" = 'slug-2' AND "activeadmin_cms_pages"."id" != 1) LIMIT 1[0m
|
793
|
+
[1m[35mSQL (0.1ms)[0m UPDATE "activeadmin_cms_pages" SET "draft_content" = ?, "content" = ?, "published" = ?, "updated_at" = ? WHERE "activeadmin_cms_pages"."id" = 1 [["draft_content", "new content"], ["content", "new content"], ["published", true], ["updated_at", Sun, 20 Oct 2013 21:42:16 UTC +00:00]]
|
794
|
+
[1m[36mActiveadminCms::Page Load (0.0ms)[0m [1mSELECT "activeadmin_cms_pages".* FROM "activeadmin_cms_pages" WHERE "activeadmin_cms_pages"."id" = ? LIMIT 1[0m [["id", 1]]
|
795
|
+
[1m[35m (0.1ms)[0m ROLLBACK TO SAVEPOINT active_record_1
|
796
|
+
[1m[36m (0.4ms)[0m [1mrollback transaction[0m
|
797
|
+
[1m[35m (0.0ms)[0m begin transaction
|
798
|
+
------------------------------
|
799
|
+
ActiveadminCmsTest: test_truth
|
800
|
+
------------------------------
|
801
|
+
[1m[36m (0.1ms)[0m [1mSAVEPOINT active_record_1[0m
|
802
|
+
[1m[35m (0.0ms)[0m RELEASE SAVEPOINT active_record_1
|
803
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
804
|
+
[1m[35m (0.0ms)[0m ROLLBACK TO SAVEPOINT active_record_1
|
805
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_cms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iskander Haziev
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ! '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: liquid
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: sqlite3
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -180,8 +194,13 @@ files:
|
|
180
194
|
- app/controllers/activeadmin_cms/application_controller.rb
|
181
195
|
- app/models/activeadmin_cms/page.rb
|
182
196
|
- app/models/activeadmin_cms/post.rb
|
197
|
+
- app/services/activeadmin_cms/composer_service.rb
|
198
|
+
- app/services/activeadmin_cms/menu_builder_service.rb
|
183
199
|
- app/services/activeadmin_cms/pages_service.rb
|
184
200
|
- app/services/activeadmin_cms/posts_service.rb
|
201
|
+
- app/services/activeadmin_cms/processors/base.rb
|
202
|
+
- app/services/activeadmin_cms/processors/parse_menu.rb
|
203
|
+
- app/services/activeadmin_cms/processors/parse_template.rb
|
185
204
|
- app/views/layouts/activeadmin_cms/application.html.erb
|
186
205
|
- config/routes.rb
|
187
206
|
- db/migrate/20131020140024_create_activeadmin_cms_posts.rb
|