meta2 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa433e368bef30a9d9fc9e8017952c5fab25a64a
4
- data.tar.gz: df9a8784fcab09b85c43e76da1a2d0ac07746901
3
+ metadata.gz: e4b44cc106dc7ebd8eb9a2f52ddbecde5f5b9a2c
4
+ data.tar.gz: 6aeb1d5d6191ee6f59f8b83bda8f3579c0174b81
5
5
  SHA512:
6
- metadata.gz: de362c12a7156c2f1e6545cadfa23896b7c78c37b018bd7600dca84684861904c3943100d12380bf2c9080a7a3f821320664164480c2b7a5456a5d11c17bff39
7
- data.tar.gz: 1f8828e55628da1bcf2c674cbc82e9b2df936170ff2a2fc1724b1fea8c9c80b9331726ab6c0ecfc08f0f6ff2066036c99350f55194287c77fe9a347bc4bd0cbe
6
+ metadata.gz: 522e6f1921c285a90cd25a19fb09542edec115ff77fda7049f4150afbde71d235a004ce4585494315f6c159beb7cd001d55623f85f842e0910898ca673d5c2cf
7
+ data.tar.gz: 5df81c838ea6c05601479e7a94a65713b02622510d93f88ce3ebe012cbfbea8951ce9fef1953714bee9237eabbc453a014ba6d8457cf99a3fddfa4d3b38d04a8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- meta2 (0.0.1)
4
+ meta2 (0.0.2)
5
5
  activesupport (>= 4.0.0, < 5)
6
6
  i18n (~> 0.7.0)
7
7
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Meta2
2
2
 
3
- TODO: Write a gem description
3
+ Implementation of the order to easily manage the meta-information for engineers and service managers. When your write i18n file or manage database through active record, put on it is reflected meta information on html.
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,9 +18,47 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install meta2
20
20
 
21
- ## Usage
21
+ ## Features ##
22
+
23
+ 1. Minimize the number of issued of SQL for system load usisng active record strategy.
24
+ 2. Implement scafoiding of the management function.
25
+
26
+
27
+ ## Supported ORMs. ##
28
+
29
+ Active record only.
30
+
31
+
32
+ ## Usage ##
33
+
34
+ 1. bundle 'meta2' gem.
35
+ 2. Create setting file for `meta2` by install command. You can use the generator for doing this ( `% rails g meta2:install` ) Setting file is created ( `config/initializers/meta2.rb` ).
36
+ 3. Basically there is not problem with default setting, if you need to change it, Plrease change in the reference of `Setting` section.
37
+ 4. Writing helper method for meta2 ( `meta_tags` ) into html head tag.
38
+ 5. Please configure the meta-information according strategry your choice for each page on your system.
39
+ 6. Then it's done.
40
+
41
+ ## Setting ##
42
+
43
+ * strategy
44
+ You can choise `:i18n` or `:activerecord` as the storage for saving meta information. default, `i18n`.
45
+
46
+ * assign_name
47
+ Default `meta2`. Basically you do not need to change.
48
+
49
+ * columns
50
+ Default `title`, `description` and `keyword`.
51
+
52
+ * logger
53
+
54
+ *logging
55
+
56
+ ## Configuration ##
57
+
58
+ ### I18n ###
59
+
60
+ ### Active record ###
22
61
 
23
- TODO: Write usage instructions here
24
62
 
25
63
  ## Contributing
26
64
 
@@ -0,0 +1,6 @@
1
+ $(function() {
2
+ $('#meta2_activerecord_section_selecter').on('change', function() {
3
+ var rpath = $(this).data('path') + '?section=' + $(this).val();
4
+ location.href = rpath;
5
+ });
6
+ });
@@ -0,0 +1,91 @@
1
+ module Meta2
2
+ class SettingsController < Meta2.config.controller_base.constantize
3
+ helper Meta2::ApplicationHelper
4
+ helper_method :app_name_from_session
5
+
6
+ before_action :activerecord_strategy?
7
+ before_action :set_setting, only: [:edit, :update, :destroy]
8
+
9
+ def index
10
+ if settings_base.blank?
11
+ redirect_to new_setting_path and return
12
+ end
13
+
14
+ @settings = settings_base.target_sections params[:section]
15
+ @settings = @settings.page(params[:page]).per(Meta2.config.per_for_paginate)
16
+ end
17
+
18
+ def new
19
+ @setting = settings_base.new app_name: app_name_from_session
20
+ end
21
+
22
+ def create
23
+ @setting = settings_base.new setting_params
24
+ if @setting.valid?(:pre_check) && @setting.save(context: @setting.section.to_sym)
25
+ session[Meta2.config.session_name] = @setting.app_name
26
+ redirect_to edit_setting_path(@setting), notice: I18n.t('meta2.setting.message.created')
27
+ else
28
+ render :new
29
+ end
30
+ end
31
+
32
+ def edit
33
+ end
34
+
35
+ def update
36
+ @setting.attributes = setting_params
37
+ if @setting.valid?(:pre_check) && @setting.save(context: @setting.section.to_sym)
38
+ redirect_to edit_setting_path(@setting), notice: I18n.t('meta2.setting.message.updated')
39
+ else
40
+ render :edit
41
+ end
42
+ end
43
+
44
+ def destroy
45
+ if %w(formats defaults).include? @setting.section
46
+ redirect_to settings_path, alert: I18n.t('meta2.setting.message.not_destroy') and return
47
+ end
48
+
49
+ @setting.destroy
50
+ redirect_to settings_path, notice: I18n.t('meta2.setting.message.destroyed')
51
+ end
52
+
53
+ def change_app
54
+ setting = Setting.find_by app_name: params[:app_name]
55
+ if setting.blank?
56
+ not_found and return
57
+ end
58
+
59
+ session[Meta2.config.session_name] = params[:app_name]
60
+
61
+ redirect_to settings_path
62
+ end
63
+
64
+
65
+ private
66
+
67
+ def set_setting
68
+ @setting = settings_base.find_by id: params[:id]
69
+ not_found if @setting.blank?
70
+ end
71
+
72
+ def setting_params
73
+ params.required(:setting).permit(:app_name, :section, :path, :name, :value, :note)
74
+ end
75
+
76
+ def settings_base
77
+ Setting.by_app_name app_name_from_session
78
+ end
79
+
80
+ def app_name_from_session
81
+ session[Meta2.config.session_name].presence || 'meta2'
82
+ end
83
+
84
+ def activerecord_strategy?
85
+ unless :active_record == Meta2.config.strategy.to_sym
86
+ Meta2.debug I18n.t('meta2.setting.message.activerecord_limited')
87
+ raise I18n.t('meta2.setting.message.activerecord_limited')
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,8 @@
1
+ module Meta2
2
+ module ApplicationHelper
3
+ def options_of_section_from_meta2_settings_for_select(form)
4
+ options = I18n.t('meta2.setting.sections').to_hash.invert
5
+ options_for_select options, selected: form.object.section.to_s
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,68 @@
1
+ module Meta2
2
+ class Setting < ActiveRecord::Base
3
+ with_options on: :pre_check do
4
+ validates :section, presence: true, inclusion: { in: Meta2.config.sections }
5
+ end
6
+
7
+ with_options on: :formats do
8
+ validates :app_name, presence: true, uniqueness: {scope: [:section, :path, :name]}
9
+ validates :name, presence: true
10
+ validates :value, presence: true, format: {with: /\A.*\%.*\Z/i, message: I18n.t('meta2.setting.message.incorrect_format_for_formats_value')}
11
+ end
12
+
13
+ with_options on: :defaults do
14
+ validates :app_name, presence: true, uniqueness: {scope: [:section, :path, :name]}
15
+ validates :name, presence: true
16
+ validates :value, presence: true
17
+ end
18
+
19
+ with_options on: :parts do
20
+ validates :app_name, presence: true, uniqueness: {scope: [:section, :path, :name]}
21
+ validates :path, presence: true
22
+ validates :name, presence: true
23
+ validates :value, presence: true
24
+ end
25
+
26
+
27
+ scope :by_app_name, ->(app_name) {
28
+ where app_name: app_name
29
+ }
30
+
31
+ scope :target_sections, ->(section_name) {
32
+ section_name = 'parts' if section_name.blank?
33
+ return unless self.sections.include? section_name
34
+ send section_name
35
+ }
36
+
37
+ scope :formats, -> {
38
+ where section: 'formats'
39
+ }
40
+
41
+ scope :defaults, -> {
42
+ where section: 'defaults'
43
+ }
44
+
45
+ scope :parts, -> {
46
+ where section: 'parts'
47
+ }
48
+
49
+ def method_missing(method, *args)
50
+ check_name = method.to_s.gsub '?', ''
51
+ unless %w(formats defaults parts).include? check_name
52
+ super(method, args) and return
53
+ end
54
+
55
+ self.section == check_name
56
+ end
57
+
58
+ class << self
59
+ def app_names
60
+ self.group(:app_name).pluck :app_name
61
+ end
62
+
63
+ def sections
64
+ Meta2.config.sections
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,40 @@
1
+ = form_for @setting, html: {class: 'form-horizontal'} do |form|
2
+
3
+ - if form.object.errors.any?
4
+ ul.list-unstyled.alert.alert-danger
5
+ - form.object.errors.full_messages.each do |message|
6
+ li = message
7
+
8
+ .form-group
9
+ label.col-xs-2.control-label = Meta2::Setting.human_attribute_name :app_name
10
+ .col-xs-10
11
+ = form.text_field :app_name, class: 'form-control', disabled: form.object.persisted?
12
+
13
+ .form-group
14
+ label.col-xs-2.control-label = Meta2::Setting.human_attribute_name :section
15
+ .col-xs-10
16
+ = form.select :section, options_of_section_from_meta2_settings_for_select(form), {}, class: 'form-control', disabled: form.object.persisted?
17
+
18
+ .form-group
19
+ label.col-xs-2.control-label = Meta2::Setting.human_attribute_name :path
20
+ .col-xs-10
21
+ = form.text_field :path, class: 'form-control', disabled: (form.object.persisted? && !form.object.parts?)
22
+
23
+ .form-group
24
+ label.col-xs-2.control-label = Meta2::Setting.human_attribute_name :name
25
+ .col-xs-10
26
+ = form.select :name, options_for_select(I18n.t('meta2.setting.defaults').invert, selected: form.object.name), {}, class: 'form-control', disabled: form.object.persisted?
27
+
28
+ .form-group
29
+ label.col-xs-2.control-label = Meta2::Setting.human_attribute_name :value
30
+ .col-xs-10
31
+ = form.text_field :value, class: 'form-control'
32
+
33
+ .form-group
34
+ label.col-xs-2.control-label = Meta2::Setting.human_attribute_name :note
35
+ .col-xs-10
36
+ = form.text_field :note, class: 'form-control'
37
+
38
+ .form-group
39
+ .col-xs-10.col-xs-offset-2
40
+ = form.submit I18n.t('meta2.setting.submit'), class: 'btn btn-warning'
@@ -0,0 +1,10 @@
1
+ tr
2
+ td.text-center = record.section
3
+ td = record.path
4
+ td = record.name
5
+ td = record.value
6
+ td = record.note
7
+ td.text-center
8
+ .btn-group
9
+ = link_to I18n.t('meta2.setting.edit'), edit_setting_path(record), class: 'btn btn-default'
10
+ = link_to I18n.t('meta2.setting.destroy'), setting_path(record), class: 'btn btn-default', method: :delete, data: {confirm: I18n.t('meta2.setting.message.destroy')}
@@ -0,0 +1,6 @@
1
+ .page-header
2
+ h1
3
+ span.pull-right = I18n.t 'meta2.setting.edit', name: cm('meta2/setting')
4
+ small = link_to 'Back', settings_path(section: @setting.section), class: 'btn btn-default btn-sm'
5
+
6
+ = render 'form'
@@ -0,0 +1,19 @@
1
+ .page-header
2
+ h1
3
+ span = "#{Meta2::Setting.model_name.human}管理"
4
+ small.pull-right = link_to I18n.t('meta2.setting.new'), new_setting_path(section: params[:section]), class: 'btn btn-default'
5
+
6
+ ul.nav.nav-tabs
7
+ - Meta2::Setting.app_names.each do |app_name|
8
+ li role="presentation" class="#{'active' if app_name == app_name_from_session}" = link_to app_name, change_app_settings_path(app_name: app_name), method: :post
9
+
10
+
11
+ table.table.table-borderd
12
+ tr
13
+ th = select_tag :section, options_for_select(I18n.t('meta2.setting.sections').to_hash.invert, selected: params[:section].presence || 'parts'), class: 'form-control', id: :meta2_activerecord_section_selecter, data: {path: settings_path}
14
+ th = cm 'meta2/setting.path'
15
+ th = cm 'meta2/setting.name'
16
+ th = cm 'meta2/setting.value'
17
+ th = cm 'meta2/setting.note'
18
+ th
19
+ = render partial: 'record', collection: @settings
@@ -0,0 +1,6 @@
1
+ .page-header
2
+ h1
3
+ span.pull-right = I18n.t 'meta2.setting.new', name: Meta2::Setting.model_name.human
4
+ small = link_to 'Back', settings_path(section: params[:section]), class: 'btn btn-default btn-sm'
5
+
6
+ = render 'form'
@@ -0,0 +1,49 @@
1
+ ja:
2
+ meta2:
3
+ setting:
4
+ new: '新規作成'
5
+ edit: '編集'
6
+ destroy: '削除'
7
+ submit: '送信する'
8
+ message:
9
+ created: '新しい情報を作成しました'
10
+ updated: '情報を更新しました'
11
+ destroyed: '情報を削除しました'
12
+ destroy: |-
13
+ 情報を削除しますか?
14
+ 削除すると元に戻せません。
15
+ not_destroy: 'フォーマット、デフォルト値は削除出来ません'
16
+ incorrect_format_for_formats_value: 'フォーマットの値には"%"を含めてください'
17
+ activerecord_limited: 'Please choise `activerecord` strategy'
18
+ sections:
19
+ formats: 'フォーマット'
20
+ defaults: 'デフォルト'
21
+ parts: 'パーツ'
22
+ defaults:
23
+ title: 'タイトル'
24
+ description: 'デスクリプション'
25
+ keywords: 'キーワード'
26
+ config:
27
+ formats:
28
+ title: '%'
29
+ description: '%'
30
+ defaults:
31
+ title: 'タイトル'
32
+ description: 'デスクリプション'
33
+ keywords: 'キーワード'
34
+ sections:
35
+ welcome:
36
+ root:
37
+ title: 'Title for top page of your serivce.'
38
+ description: 'Description for top page of your service.'
39
+ activerecord:
40
+ models:
41
+ meta2/setting: 'メタ情報'
42
+ attributes:
43
+ meta2/setting:
44
+ app_name: 'アプリ識別'
45
+ section: 'セクション'
46
+ path: 'パス'
47
+ name: '名前'
48
+ value: '値'
49
+ note: 'メモ'
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Meta2::Engine.routes.draw do
2
+ resources :settings do
3
+ collection do
4
+ post 'change_app'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Meta2
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Meta2
4
+ end
5
+ end
@@ -4,7 +4,14 @@ module Meta2
4
4
  def meta_tags
5
5
  resolver = instance_variable_get "@#{Meta2.config.assign_name}"
6
6
 
7
- resolver.detect.to_html(resolver.context).html_safe
7
+ html_source = resolver.detect.to_html(resolver.context)
8
+ unless Rails.env.production?
9
+ asist_message = resolver.options[:prefixes].map do |prefix|
10
+ '%s.%s' % [prefix, resolver.options[:template]]
11
+ end.join "\n"
12
+ html_source += "<!--Meta2 path hinting.\n#{asist_message} -->\n"
13
+ end
14
+ html_source.html_safe
8
15
  end
9
16
  end
10
17
  end
data/lib/meta2/railtie.rb CHANGED
@@ -4,11 +4,17 @@ module Meta2
4
4
 
5
5
  initializer 'meta2' do |app|
6
6
  config = app.config.meta2
7
- config.strategy = :i18n
8
- config.assign_name = :meta2
9
- config.columns = %w{title description keywords}
10
- config.logger = Rails.logger
11
- config.logging = true
7
+
8
+ # Default settings. all subject can be changed.
9
+ config.strategy = :i18n
10
+ config.assign_name = :meta2
11
+ config.sections = %w{formats defaults parts}
12
+ config.columns = %w{title description keywords}
13
+ config.logger = Rails.logger
14
+ config.logging = true
15
+ config.controller_base = 'ApplicationController'
16
+ config.per_for_paginate = 20
17
+ config.session_name = '___current_meta2_app_name___'
12
18
  end
13
19
  end
14
20
  end
@@ -43,7 +43,7 @@ module Meta2
43
43
  end
44
44
 
45
45
  def targets
46
- Meta2::Models::MetaSetting.where app_name: @config[:assign_name]
46
+ Meta2::Setting.where app_name: @config[:assign_name]
47
47
  end
48
48
  end
49
49
  end
@@ -28,7 +28,7 @@ module Meta2
28
28
  private
29
29
 
30
30
  def catch_path(namespace)
31
- path = "#{@config.assign_name}.#{namespace}"
31
+ path = "#{@config.assign_name}.config.#{namespace}"
32
32
  Meta2.debug "#{namespace} path:#{path}"
33
33
  content = ::I18n.t path, default: FAILURE_KEYWORD
34
34
  FAILURE_KEYWORD == content.to_s ? nil : content
@@ -25,7 +25,7 @@ module Meta2
25
25
 
26
26
  def build_path(prefix)
27
27
  path_prefix = prefix.gsub '/', '.'
28
- '%s.parts.%s.%s' % [
28
+ '%s.config.parts.%s.%s' % [
29
29
  @config.assign_name, path_prefix, @options[:template]
30
30
  ]
31
31
  end
data/lib/meta2/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Meta2
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/meta2.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'active_support/dependencies'
2
+ require 'meta2/engine'
2
3
 
3
4
  module Meta2
4
5
  autoload :Absorber, 'meta2/absorber'
data/meta2.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["manabu.oshiro"]
10
10
  spec.email = ["manabu.oshiro@zinbun.com"]
11
11
  spec.summary = %q{Implementation of the order to easily manage the meta-information.}
12
- spec.description = %q{Implementation of the order to easily manage the meta-information for enginners and service managers.}
12
+ spec.description = %q{Implementation of the order to easily manage the meta-information for engineers and service managers. When your write i18n file or manage database through active record, put on it is reflected meta information on html.}
13
13
  spec.homepage = "https://github.com/manoshiro/meta2"
14
14
  spec.license = "MIT"
15
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meta2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - manabu.oshiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-02 00:00:00.000000000 Z
11
+ date: 2015-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -87,7 +87,8 @@ dependencies:
87
87
  - !ruby/object:Gem::Version
88
88
  version: '3.3'
89
89
  description: Implementation of the order to easily manage the meta-information for
90
- enginners and service managers.
90
+ engineers and service managers. When your write i18n file or manage database through
91
+ active record, put on it is reflected meta information on html.
91
92
  email:
92
93
  - manabu.oshiro@zinbun.com
93
94
  executables: []
@@ -102,6 +103,17 @@ files:
102
103
  - LICENSE.txt
103
104
  - README.md
104
105
  - Rakefile
106
+ - app/assets/javascripts/meta2/activerecord-manager.js
107
+ - app/controllers/meta2/settings_controller.rb
108
+ - app/helpers/meta2/application_helper.rb
109
+ - app/models/meta2/setting.rb
110
+ - app/views/meta2/settings/_form.html.slim
111
+ - app/views/meta2/settings/_record.html.slim
112
+ - app/views/meta2/settings/edit.html.slim
113
+ - app/views/meta2/settings/index.html.slim
114
+ - app/views/meta2/settings/new.html.slim
115
+ - config/locales/meta2.ja.yml
116
+ - config/routes.rb
105
117
  - lib/generators/active_record/meta2_generator.rb
106
118
  - lib/generators/active_record/templates/migration.rb
107
119
  - lib/generators/meta2/install_generator.rb
@@ -111,8 +123,8 @@ files:
111
123
  - lib/meta2.rb
112
124
  - lib/meta2/absorber.rb
113
125
  - lib/meta2/alias_method_chains.rb
126
+ - lib/meta2/engine.rb
114
127
  - lib/meta2/helpers/action_view_extension.rb
115
- - lib/meta2/models/meta_setting.rb
116
128
  - lib/meta2/rails.rb
117
129
  - lib/meta2/railtie.rb
118
130
  - lib/meta2/resolver.rb
@@ -1,6 +0,0 @@
1
- module Meta2
2
- module Models
3
- class MetaSetting < ActiveRecord::Base
4
- end
5
- end
6
- end