rcms 0.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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cmshelper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 ruslan.palagin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Cmshelper
2
+
3
+ - Allows to create pages with editable content
4
+ - Allows set/edit meta tags for each request
5
+ - Some useful helpers
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rcms', github: 'r1dd1ck777/rcms'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rcms
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## License
28
+
29
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
30
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cmshelper"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,51 @@
1
+ ru:
2
+ rcms:
3
+ none: 1
4
+ page:
5
+ not_found: Информационная страничка "%{slug}" не найдена.
6
+ activerecord:
7
+ models:
8
+ rcms/page:
9
+ one: Страницу
10
+ few: Страниц
11
+ many: Страниц
12
+ other: Страницы
13
+
14
+ rcms/partial:
15
+ one: Текст
16
+ few: Текса
17
+ many: Текстов
18
+ other: Тексты
19
+
20
+ rcms/meta_page:
21
+ one: Мета страницу
22
+ few: Мета страниц
23
+ many: Мета страниц
24
+ other: Мета страницы
25
+ rcms/meta_tag:
26
+ one: Мета тег
27
+ few: Мета тега
28
+ many: Мета тегов
29
+ other: Мета теги
30
+
31
+ attributes:
32
+ rcms/page:
33
+ title: Заголовок
34
+ slug: Url-ключ
35
+ text: Текст
36
+ slug_hint: "Url странички: %{path}"
37
+ updated_at: Редактировано
38
+ rcms/partial:
39
+ placement: Разположение
40
+ description: Описание (для админа)
41
+ text: Текст
42
+ updated_at: Редактировано
43
+ rcms/meta_page:
44
+ path: Путь
45
+ path_hint: например "/p-some-product-name"
46
+ meta_tags: Мета теги
47
+ updated_at: Редактировано
48
+ rcms/meta_tag:
49
+ key: Название тега
50
+ value: Значение
51
+
@@ -0,0 +1,41 @@
1
+ class RcmsGenerator < Rails::Generators::Base
2
+ include Rails::Generators::Migration
3
+ source_root File.expand_path("../templates", __FILE__)
4
+
5
+ def self.next_migration_number(dirname)
6
+ Time.now.strftime("%Y%m%d%H%M%S")
7
+ end
8
+
9
+ def create_cmshelper_migration
10
+ migration_template "migration.rb", File.join('db/migrate', "create_rcms_tables.rb")
11
+ end
12
+
13
+ def create_model_files
14
+ %w(meta_page.rb meta_tag.rb page.rb partial.rb).each do |name|
15
+ copy_file "app/models/rcms/#{name}"
16
+ end
17
+ end
18
+
19
+ def create_admin_files
20
+ %w(meta_page.rb page.rb partial.rb).each do |name|
21
+ copy_file "app/admin/rcms/#{name}"
22
+ end
23
+ end
24
+
25
+ def create_controllers
26
+ %w(pages_controller.rb).each do |name|
27
+ copy_file "app/controllers/rcms/#{name}"
28
+ end
29
+ end
30
+
31
+ def create_pages_views
32
+ %w(show.html.slim).each do |name|
33
+ copy_file "app/views/rcms/pages/#{name}"
34
+ end
35
+ end
36
+
37
+ def patch_controller
38
+ insert_into_file "config/routes.rb", " get 'page-:slug' => 'rcms/pages#show', as: :rcms_page\n", :after => "Rails.application.routes.draw do\n"
39
+ insert_into_file "app/controllers/application_controller.rb", " include Rcms::ApplicationController\n", :after => "class ApplicationController < ActionController::Base\n"
40
+ end
41
+ end
@@ -0,0 +1,17 @@
1
+ ActiveAdmin.register Rcms::MetaPage do
2
+ permit_params :path, meta_tags_attributes:[:id, :key, :value, :_destroy]
3
+
4
+ form do |f|
5
+ f.inputs do
6
+ f.input :path, hint: t("activerecord.attributes.rcms/meta_page.path_hint")
7
+ f.has_many :meta_tags, allow_destroy: true, new_record: true do |cf|
8
+ cf.input :key
9
+ cf.input :value
10
+ end
11
+ end
12
+ f.actions
13
+ end
14
+
15
+ filter :path
16
+
17
+ end
@@ -0,0 +1,28 @@
1
+ ActiveAdmin.register Rcms::Page do
2
+ # include AdminRedirects
3
+
4
+ permit_params :slug, :title, :text
5
+
6
+ form do |f|
7
+ f.inputs do
8
+ f.input :title
9
+ f.input :slug, hint: f.object.persisted? ? (t("activerecord.attributes.rcms/page.slug_hint", path: rcms_page_path(f.object))) : nil
10
+ f.inputs t("activerecord.attributes.rcms/page.text") do
11
+ f.cktext_area :text
12
+ end
13
+ end
14
+ f.actions
15
+ end
16
+
17
+ index do
18
+ selectable_column
19
+ column :id
20
+ column :slug
21
+ column :title
22
+ column :updated_at
23
+ actions
24
+ end
25
+
26
+ filter :slug
27
+ filter :title
28
+ end
@@ -0,0 +1,25 @@
1
+ ActiveAdmin.register Rcms::Partial do
2
+ # include AdminRedirects
3
+
4
+ config.filters = false
5
+ permit_params :text, :placement, :description
6
+
7
+ form do |f|
8
+ f.inputs do
9
+ f.input :placement
10
+ f.input :description
11
+ f.inputs do
12
+ f.cktext_area :text
13
+ end
14
+ end
15
+
16
+ f.actions
17
+ end
18
+
19
+ index do
20
+ column :placement
21
+ column :description
22
+ column :updated_at
23
+ actions
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ class Rcms::PagesController < ApplicationController
2
+ def show
3
+ @rcms_page = retrieve_rcms_page params[:slug]
4
+ unless @rcms_page
5
+ redirect_to root_path, flash: {warning: t("rcms.page.not_found", slug: params[:slug])}
6
+ end
7
+
8
+ rcms_menu @rcms_page.slug
9
+ end
10
+
11
+ protected
12
+ def retrieve_rcms_page slug_or_id
13
+ Rcms::Page.find slug_or_id
14
+ rescue
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ class Rcms::MetaPage < ActiveRecord::Base
2
+ self.table_name = 'rcms_meta_pages'
3
+
4
+ has_many :meta_tags, as: :meta_managable, :dependent => :destroy, class_name: Rcms::MetaTag
5
+ accepts_nested_attributes_for :meta_tags
6
+
7
+ after_initialize :create_meta_tags
8
+
9
+ protected
10
+
11
+ def create_meta_tags
12
+ if !persisted? && self.meta_tags.empty?
13
+ self.meta_tags.new(key: :title)
14
+ self.meta_tags.new(key: :description)
15
+ self.meta_tags.new(key: :keywords)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ class Rcms::MetaTag < ActiveRecord::Base
2
+ self.table_name = 'rcms_meta_tags'
3
+
4
+ belongs_to :meta_managable, polymorphic: true, touch: true
5
+ end
@@ -0,0 +1,16 @@
1
+ class Rcms::Page < ActiveRecord::Base
2
+ self.table_name = 'rcms_pages'
3
+
4
+ extend FriendlyId
5
+ friendly_id :title, use: [:slugged, :finders]
6
+
7
+ def meta_title
8
+ self.title
9
+ end
10
+
11
+ protected
12
+
13
+ def should_generate_new_friendly_id?
14
+ !slug.present?
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ class Rcms::Partial < ActiveRecord::Base
2
+ self.table_name = 'rcms_partials'
3
+
4
+ class << self
5
+ def _ key
6
+ partial = find_by placement: key
7
+ partial.nil? ? "Rscms::CmsPartial #{key}" : partial.text
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ .rcms-page-show-content
2
+ .paper-panel
3
+ h2
4
+ = @rcms_page.title
5
+
6
+ div
7
+ == @rcms_page.text
8
+
@@ -0,0 +1,45 @@
1
+ class CreateRcmsTables < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :rcms_partials do |t|
4
+ t.string :placement
5
+ t.string :description
6
+ t.text :text
7
+
8
+ t.timestamps
9
+ end
10
+ add_index :rcms_partials, :placement, unique: true
11
+
12
+ create_table :rcms_meta_tags do |t|
13
+ t.string :key
14
+ t.text :text
15
+ t.string :value
16
+ t.references :meta_managable, polymorphic: true
17
+
18
+ t.timestamps
19
+ end
20
+
21
+ create_table :rcms_meta_pages do |t|
22
+ t.string :path
23
+
24
+ t.timestamps
25
+ end
26
+ add_index :rcms_meta_pages, :path, unique: true
27
+
28
+ create_table :rcms_pages do |t|
29
+ t.string :slug
30
+ t.string :title
31
+ t.text :text
32
+
33
+ t.timestamps
34
+ end
35
+ add_index :rcms_pages, :slug, unique: true
36
+
37
+ end
38
+
39
+ def self.down
40
+ drop_table :rcms_partials
41
+ drop_table :rcms_meta_tags
42
+ drop_table :rcms_meta_pages
43
+ drop_table :rcms_pages
44
+ end
45
+ end
@@ -0,0 +1,56 @@
1
+ module Rcms
2
+ module ApplicationController
3
+ def self.included(base)
4
+ base.class_eval do
5
+ include InstanceMethods
6
+ extend ActiveModel::Callbacks unless base.respond_to? :run_callbacks
7
+ define_model_callbacks :render
8
+ before_render :use_meta_page, :update_meta_title
9
+ helper_method :rcms_menu, :rcms_menu_class
10
+ end
11
+ end
12
+
13
+ module InstanceMethods
14
+ def rcms_menu key, domain = nil
15
+ @rcms_menu = "#{domain}#{key}"
16
+ end
17
+
18
+ def rcms_menu_class key, domain = nil
19
+ @rcms_menu == "#{domain}#{key}" ? 'active' : ''
20
+ end
21
+
22
+ def apply_meta_tags object
23
+ meta_tags = object.respond_to?(:meta_tags) ? object.meta_tags : object
24
+
25
+ if meta_tags.is_a?(Hash)
26
+ set_meta_tags meta_tags
27
+ else
28
+ meta_tags.each do |mt|
29
+ set_meta_tags mt.key => mt.value if mt.value.present?
30
+ end
31
+ end
32
+ end
33
+
34
+ protected
35
+
36
+ def render *args
37
+ run_callbacks :render do
38
+ super
39
+ end
40
+ end
41
+
42
+ def use_meta_page
43
+ if request.fullpath != '/'
44
+ path = request.fullpath.scan(/(\/[^#\?]+)/)[0][0]
45
+ @meta_page = Rcms::MetaPage.find_by(path: path)
46
+ apply_meta_tags @meta_page if @meta_page
47
+ end
48
+ rescue
49
+ end
50
+
51
+ def update_meta_title
52
+ set_meta_tags :title => "#{meta_tags[:title]} - #{params[:page]}" if params[:page]
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,7 @@
1
+ class Rcms::Router
2
+ def self.routes router
3
+ router.instance_exec do
4
+ get 'info-:slug' => 'rcms/pages#show', as: :rcms_page
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Rcms
2
+ VERSION = "0.1.0"
3
+ end
data/lib/rcms.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "rcms/version"
2
+
3
+ module Rcms
4
+ autoload :ApplicationController, 'rcms/application_controller'
5
+ autoload :Router, 'rcms/router'
6
+
7
+ class Engine < Rails::Engine
8
+ end
9
+ end
10
+
11
+ # ActiveSupport.on_load :action_controller do
12
+ # include Rcms::ApplicationController
13
+ # end
data/rcms.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rcms/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rcms"
8
+ spec.version = Rcms::VERSION
9
+ spec.authors = ["ruslan.palagin"]
10
+ spec.email = ["ruslan.palagin.ck@gmail.com"]
11
+
12
+ spec.summary = %q{It will helps you to manage your cms parts of site}
13
+ spec.description = %q{...}
14
+ spec.homepage = "https://github.com/r1dd1ck777"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = ""
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rcms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ruslan.palagin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: "..."
42
+ email:
43
+ - ruslan.palagin.ck@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".idea/.name"
50
+ - ".idea/.rakeTasks"
51
+ - ".idea/cmshelper.iml"
52
+ - ".idea/misc.xml"
53
+ - ".idea/modules.xml"
54
+ - ".idea/vcs.xml"
55
+ - ".idea/workspace.xml"
56
+ - Gemfile
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - bin/console
61
+ - bin/setup
62
+ - config/locales/rcms.ru.yml
63
+ - lib/generators/rcms_generator.rb
64
+ - lib/generators/templates/app/admin/rcms/meta_page.rb
65
+ - lib/generators/templates/app/admin/rcms/page.rb
66
+ - lib/generators/templates/app/admin/rcms/partial.rb
67
+ - lib/generators/templates/app/controllers/rcms/pages_controller.rb
68
+ - lib/generators/templates/app/models/rcms/meta_page.rb
69
+ - lib/generators/templates/app/models/rcms/meta_tag.rb
70
+ - lib/generators/templates/app/models/rcms/page.rb
71
+ - lib/generators/templates/app/models/rcms/partial.rb
72
+ - lib/generators/templates/app/views/rcms/pages/show.html.slim
73
+ - lib/generators/templates/migration.rb
74
+ - lib/rcms.rb
75
+ - lib/rcms/application_controller.rb
76
+ - lib/rcms/router.rb
77
+ - lib/rcms/version.rb
78
+ - rcms.gemspec
79
+ homepage: https://github.com/r1dd1ck777
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.4.6
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: It will helps you to manage your cms parts of site
103
+ test_files: []