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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDI0ODY2M2M0OWQwZTBhYmIzZmEyMmZiNTQzNjU4NzYzOTU3ZTQyZg==
4
+ M2QxNWQzOTJmMjc5NzhmZWU1YThkNDhiODYyYjUzNDBlZGIyYzViMA==
5
5
  data.tar.gz: !binary |-
6
- NWY3MmM0N2EzOGM4MDBkNDRlMDY1MzBkZDJhNjJhZWE4YWQ0ODI1OA==
6
+ ZDQxZTRiNjRhNmQ4MGYwMzNjOGRjYTExMmFiMTdjYzAyMjdmOTE0Zg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MjI3NzVjOTNmNjk2M2Y4MTBlN2JmNGFhZWIyMjA2MzA2YmM4OWNhNWM5MmU1
10
- ZDY0N2ZlN2YwMzNmZmExOWVkM2UxZjMyNTBjYTE1NWZkNzdjYWUxODljMjY1
11
- ZjMzOTYyMmNhMjJhZjYzYzQxMjE0NzA5OGE3Y2MzOGRmMTUwZDU=
9
+ NzkzOWUwNTg0NmRlYWE2ZmU5ZjJiYzM5NTVlYWQ4MTdhMWU5YjNmYjkyYTZk
10
+ MTI1MjQ2NjcwY2QzYWU3MjliNmE0MjMxN2ViNWFjYzdjNjIxNzU5N2U0YzBj
11
+ NWQzNmI2OWNlYTkzZWRmYzZhODQxYTA3OGQwNGFmODBhMGUwNDU=
12
12
  data.tar.gz: !binary |-
13
- MzlmY2VmMjliNjVkOWY2ZGNlMjc5N2NlMDUxODM1YWEwYmYyN2FiY2Q1MjY4
14
- YzdkZWY3YjBmN2M2NmE0ZWEyMzU5MjM2M2Q3YTA5ZTM5MzJiMjc0MWZjMjlj
15
- ZjU5OGM4NGJlN2FlODI1OGMyNmUyZDdlYTg5Mzg1ZjNkYWY5YTM=
13
+ YTNkM2JlM2E0YTIwYmRlZGRkMjljZDhmNDRjMDExMjVhNWYwODZmN2Q4MGFl
14
+ MTM5Mjg2ZWM1MGQ3MGVlMjk3MTFlZGQxMGVkNTY3ZDM2NzdiMDk2MTExYmRj
15
+ YTViNTU3MGNhYmRkYTc1ZDBhMTljMGZhNzZjOGE2Y2VlMWUwNTk=
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.0.6
2
+ * Added liquid processor with menu builder
3
+
1
4
  == 0.0.4 - 0.0.5
2
5
  * Small fixes
3
6
 
@@ -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,17 @@
1
+ class ActiveadminCms::Processors::Base
2
+ attr_accessor :html
3
+
4
+ def initialize(html, options = {})
5
+ @html = html
6
+ @options = options
7
+ end
8
+
9
+ def process!
10
+ process
11
+ html
12
+ end
13
+
14
+ def option(opt)
15
+ @options[opt.to_sym]
16
+ end
17
+ 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
+
@@ -0,0 +1,9 @@
1
+ class ActiveadminCms::Processors::ParseTemplate < ActiveadminCms::Processors::Base
2
+ def process
3
+ variables = {
4
+ 'page' => option(:page),
5
+ 'menu' => option(:menu)
6
+ }
7
+ @html = Liquid::Template.parse(@html).render(variables)
8
+ end
9
+ end
@@ -1,6 +1,7 @@
1
1
  require 'activeadmin'
2
2
  require 'ace-rails-ap'
3
3
  require 'jquery-rails'
4
+ require 'liquid'
4
5
  begin
5
6
  require 'acts-as-taggable-on'
6
7
  rescue LoadError
@@ -1,3 +1,3 @@
1
1
  module ActiveadminCms
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
Binary file
@@ -748,3 +748,58 @@ ActiveadminCmsTest: test_truth
748
748
   (0.0ms) SAVEPOINT active_record_1
749
749
   (0.0ms) ROLLBACK TO SAVEPOINT active_record_1
750
750
   (0.1ms) rollback transaction
751
+  (1.2ms) DELETE FROM "activeadmin_cms_posts";
752
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
753
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'activeadmin_cms_posts';
754
+  (1.0ms) DELETE FROM "activeadmin_cms_pages";
755
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
756
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'activeadmin_cms_pages';
757
+  (0.1ms) begin transaction
758
+ -----------------------------------------------------
759
+ #publish: test_0001_should change status to published
760
+ -----------------------------------------------------
761
+  (0.0ms) SAVEPOINT active_record_1
762
+  (0.0ms) RELEASE SAVEPOINT active_record_1
763
+  (0.0ms) SAVEPOINT active_record_1
764
+ SQL (25.8ms) INSERT INTO "activeadmin_cms_posts" ("content", "created_at", "title", "updated_at") VALUES (?, ?, ?, ?) [["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
+ SQL (0.2ms) 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
+ ActiveadminCms::Post Load (0.1ms) SELECT "activeadmin_cms_posts".* FROM "activeadmin_cms_posts" WHERE "activeadmin_cms_posts"."id" = ? LIMIT 1 [["id", 1]]
767
+  (0.1ms) ROLLBACK TO SAVEPOINT active_record_1
768
+  (0.4ms) rollback transaction
769
+  (0.0ms) begin transaction
770
+ -----------------------------------------------------
771
+ #publish: test_0001_should change status to published
772
+ -----------------------------------------------------
773
+  (0.1ms) SAVEPOINT active_record_1
774
+  (0.0ms) RELEASE SAVEPOINT active_record_1
775
+  (0.0ms) SAVEPOINT active_record_1
776
+ ActiveadminCms::Page Exists (0.1ms) SELECT 1 AS one FROM "activeadmin_cms_pages" WHERE "activeadmin_cms_pages"."slug" = 'slug-1' LIMIT 1
777
+ SQL (0.5ms) 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-1"], ["title", "Foo page"], ["updated_at", Sun, 20 Oct 2013 21:42:16 UTC +00:00]]
778
+ ActiveadminCms::Page Exists (0.1ms) SELECT 1 AS one FROM "activeadmin_cms_pages" WHERE ("activeadmin_cms_pages"."slug" = 'slug-1' AND "activeadmin_cms_pages"."id" != 1) LIMIT 1
779
+ SQL (0.2ms) UPDATE "activeadmin_cms_pages" SET "content" = ?, "published" = ?, "updated_at" = ? WHERE "activeadmin_cms_pages"."id" = 1 [["content", nil], ["published", true], ["updated_at", Sun, 20 Oct 2013 21:42:16 UTC +00:00]]
780
+ ActiveadminCms::Page Load (0.1ms) SELECT "activeadmin_cms_pages".* FROM "activeadmin_cms_pages" WHERE "activeadmin_cms_pages"."id" = ? LIMIT 1 [["id", 1]]
781
+  (0.1ms) ROLLBACK TO SAVEPOINT active_record_1
782
+  (0.5ms) rollback transaction
783
+  (0.1ms) begin transaction
784
+ --------------------------------------------------
785
+ #publish: test_0002_should move content from draft
786
+ --------------------------------------------------
787
+  (0.0ms) SAVEPOINT active_record_1
788
+  (0.0ms) RELEASE SAVEPOINT active_record_1
789
+  (0.0ms) SAVEPOINT active_record_1
790
+ ActiveadminCms::Page Exists (0.1ms) SELECT 1 AS one FROM "activeadmin_cms_pages" WHERE "activeadmin_cms_pages"."slug" = 'slug-2' LIMIT 1
791
+ SQL (0.3ms) 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
+ ActiveadminCms::Page Exists (0.1ms) SELECT 1 AS one FROM "activeadmin_cms_pages" WHERE ("activeadmin_cms_pages"."slug" = 'slug-2' AND "activeadmin_cms_pages"."id" != 1) LIMIT 1
793
+ SQL (0.1ms) 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
+ ActiveadminCms::Page Load (0.0ms) SELECT "activeadmin_cms_pages".* FROM "activeadmin_cms_pages" WHERE "activeadmin_cms_pages"."id" = ? LIMIT 1 [["id", 1]]
795
+  (0.1ms) ROLLBACK TO SAVEPOINT active_record_1
796
+  (0.4ms) rollback transaction
797
+  (0.0ms) begin transaction
798
+ ------------------------------
799
+ ActiveadminCmsTest: test_truth
800
+ ------------------------------
801
+  (0.1ms) SAVEPOINT active_record_1
802
+  (0.0ms) RELEASE SAVEPOINT active_record_1
803
+  (0.0ms) SAVEPOINT active_record_1
804
+  (0.0ms) ROLLBACK TO SAVEPOINT active_record_1
805
+  (0.0ms) rollback transaction
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.5
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