changeful 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aa995530b08a1b27bae9dde22b5b2fc9b30a9078
4
+ data.tar.gz: 898b7a74ab585b3a2b5436e69c0f2b77b7fb7925
5
+ SHA512:
6
+ metadata.gz: 84c648d6662c2f964a1721c9dd2d0ca4a9d34532b59d76e3cc2887724e844e703c787d35d22b99c44bac2ab41700a505ad8527ae689506ae581fd105c1cea41d
7
+ data.tar.gz: 568cd1deb6c9253a5f708b477b9ec932f2849ceec02264cc263a1adae9b79d218920e9fc936d1c138526281a226f1fac5f34ae06827bcc552a0282941a4497d4
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/tmp/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ changeful
@@ -0,0 +1 @@
1
+ ruby-2.2.3
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in changeful.gemspec
4
+
5
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Wayne Tng
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.
@@ -0,0 +1,169 @@
1
+ # Changeful
2
+
3
+ [![Build Status](https://travis-ci.org/futureworkz/changeful.svg?branch=master)](https://travis-ci.org/futureworkz/changeful)
4
+ [![Dependency Status](https://gemnasium.com/futureworkz/changeful.svg)](https://gemnasium.com/futureworkz/changeful)
5
+ [![Code Climate](https://codeclimate.com/github/futureworkz/changeful/badges/gpa.svg)](https://codeclimate.com/github/futureworkz/changeful)
6
+ [![Test Coverage](https://codeclimate.com/github/futureworkz/changeful/badges/coverage.svg)](https://codeclimate.com/github/futureworkz/changeful/coverage)
7
+ [![Inline docs](http://inch-ci.org/github/futureworkz/changeful.svg)](http://inch-ci.org/github/futureworkz/changeful)
8
+ [![security](https://hakiri.io/github/futureworkz/changeful/master.svg)](https://hakiri.io/github/futureworkz/changeful/master)
9
+
10
+ Do you need to allow your administrator to edit the static content of your views?
11
+
12
+ Changeful is a gem that converts your static content in your views to be stored into database. Thereafter, administrator can use RailsAdmin or Active Admin to edit the static content.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'changeful'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ ```ruby
25
+ $ bundle install
26
+ ```
27
+
28
+ Or install it yourself as:
29
+
30
+ ```ruby
31
+ $ gem install changeful
32
+ ```
33
+
34
+ After you install Changeful to your Gemfile, you need to run the generator:
35
+
36
+ ```ruby
37
+ rails generate changeful:install
38
+ ```
39
+
40
+ This will generate the migration needed for Changeful
41
+
42
+ Run the migration to update the schema
43
+
44
+ ```ruby
45
+ rake db:migrate
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ ### ERB
51
+ ```ruby
52
+ <h1><%= changeful_content(:about_us_title) %></h1>
53
+
54
+ <div class='about-us-content'>
55
+ <%= changeful_content :about_us_content do %>
56
+ <p>You can also include HTML content as the default content in a block.</p>
57
+ <div class='more-content'>Nested tags are also okay.</div>
58
+ <% end %>
59
+ </div>
60
+ ```
61
+
62
+ ### HAML
63
+ ```ruby
64
+ %h1= changeful_content(:about_us_title)
65
+ .about-us-content
66
+ = changeful_content :about_us_content do
67
+ %p You can also include HTML content as the default content in a block.
68
+ .more-content Nested tags are also okay.
69
+ ```
70
+
71
+ ### Slim
72
+ ```ruby
73
+ h1 = changeful_content(:about_us_title)
74
+
75
+ .about-us-content
76
+ = changeful_content :about_us_content do
77
+ p You can also include HTML content as the default content in a block.
78
+ .more-content Nested tags are also okay.
79
+ ```
80
+
81
+ The view helper method `changeful_content` will return the content found in Changeful database. You can also set a default if there is no content found.
82
+
83
+ ## Available Options
84
+
85
+ Key | Accepted Values | What it does
86
+ ---|---|---
87
+ `default` | String | It sets the default content to return if the key is not found in database
88
+ `type` | `:plain`, `:html` | It tells backend gems to display the correct input field in the backend
89
+
90
+ ## More Examples
91
+
92
+ ```ruby
93
+ # In your views
94
+ changeful_content(:about_us_title)
95
+ changeful_content(:about_us_title, default: 'About Us')
96
+ changeful_content(:about_us_title, default: 'About Us', type: :plain)
97
+
98
+ # Or you can use the shorter method alias cc
99
+ cc :about_us_title
100
+ cc :about_us_title, default: 'About Us'
101
+ cc :about_us_title, default: 'About Us', type: :plain
102
+ ```
103
+
104
+ ## Integration with back-end
105
+
106
+ ### ActiveAdmin
107
+ Currently it only work well with ActiveAdmin
108
+
109
+ Register the model with ActiveAdmin
110
+
111
+ ```ruby
112
+ rails g active_admin:resource Changeful::Content
113
+ ```
114
+
115
+ By default it will create `changeful_content.rb` in `app/admin` folder
116
+
117
+ #### Configuration for ActiveAdmin
118
+
119
+ Copy the setup below to `changeful_content.rb`
120
+
121
+ Note: the example below is using `ckeditor` gem, replace the editor accordingly.
122
+
123
+ ```ruby
124
+ ActiveAdmin.register Changeful::Content do
125
+ permit_params :content
126
+ actions :all, except: [:new]
127
+
128
+ index do
129
+ selectable_column
130
+ id_column
131
+ column :key, ->(row) { row.key.titleize }
132
+ column :content
133
+ column :updated_at
134
+ actions
135
+ end
136
+
137
+ show do
138
+ attributes_table do
139
+ row :id
140
+ row :file_path
141
+ row :key
142
+ row :content
143
+ row :updated_at
144
+ end
145
+ end
146
+
147
+ form do |f|
148
+ f.inputs 'Details' do
149
+ input :key, input_html: { disabled: true }
150
+ if f.object.view_type == 'html'
151
+ input :content, as: :ckeditor
152
+ else
153
+ input :content
154
+ end
155
+ end
156
+ actions
157
+ end
158
+ end
159
+ ```
160
+ ## Contributing
161
+
162
+ 1. Fork it ( https://github.com/futureworkz/changeful/fork )
163
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
164
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
165
+ 4. Push to the branch (`git push origin my-new-feature`)
166
+ 5. Create a new Pull Request
167
+
168
+ ## License
169
+ Changeful is Copyright © 2015 Futureworkz Pte Ltd. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "changeful"
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
@@ -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,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'changeful/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "changeful"
8
+ spec.version = Changeful::VERSION
9
+ spec.authors = ["Wayne Tng"]
10
+ spec.email = ["wayne@futureworkz.com"]
11
+
12
+ spec.summary = %q{Make your static contents editable in database}
13
+ spec.description = %q{Changeful is a gem that converts your static content in your views to be stored into database. Thereafter, administrator can use RailsAdmin or Active Admin to edit the static content.}
14
+ spec.homepage = "https://github.com/futureworkz/changeful"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "rails", "> 4.2.0"
23
+
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "sqlite3"
26
+ spec.add_development_dependency "rspec-rails"
27
+ spec.add_development_dependency "generator_spec"
28
+ spec.add_development_dependency "shoulda-matchers"
29
+ end
@@ -0,0 +1,12 @@
1
+ require "changeful/version"
2
+ require "changeful/models/changeful_content"
3
+ require "changeful/helpers/view_helpers"
4
+ require "active_support/lazy_load_hooks"
5
+
6
+ ActiveSupport.on_load(:action_view) do
7
+ include Changeful::ViewHelpers
8
+ end
9
+
10
+ module Changeful # :nodoc:
11
+ # Your code goes here...
12
+ end
@@ -0,0 +1,55 @@
1
+ require_relative '../models/changeful_content'
2
+ require 'action_view/helpers/output_safety_helper'
3
+ require 'action_view/helpers/capture_helper'
4
+
5
+ module Changeful
6
+ # The Changeful ViewHelpers expose the methods to be used in view
7
+ # to make the static content editable
8
+ module ViewHelpers
9
+ include ActionView::Helpers::CaptureHelper
10
+ include ActionView::Helpers::OutputSafetyHelper
11
+ # Returns a content based on a key and store in the database if it does not exist
12
+ #
13
+ # @example
14
+ # changeful_content(:about_us_title)
15
+ # changeful_content(:about_us_title, default: 'About Us')
16
+ # changeful_content(:about_us_title, default: 'About Us', type: :plain)
17
+ #
18
+ # cc :about_us_title
19
+ # cc :about_us_title, default: 'About Us'
20
+ # cc :about_us_title, default: 'About Us', type: :plain
21
+ #
22
+ # @param key [Symbol] A unique key in the view file to be referenced
23
+ # @param options [Hash] Additional configuration options (refer below)
24
+ # @option options [Symbol] :default It sets the default content to return if the key is not found in database
25
+ # @option options [Symbol] :type Specify the type of input to be displayed in the backend. Accepted types are :plain, :html
26
+ #
27
+ # @return [String] a content based on a key
28
+ def changeful_content(key, options = {})
29
+ contents ||= Content.all_contents_in(current_view)
30
+
31
+ if contents.present?
32
+ contents.each do |datum|
33
+ return raw(datum.content) if datum.key == key.to_s
34
+ end
35
+ end
36
+
37
+ content = options.delete(:default) || capture(&proc)
38
+ view_type = options.delete(:type) || :plain
39
+ Content.create!(key: key,
40
+ content: content,
41
+ view_type: view_type,
42
+ file_path: current_view)
43
+
44
+ return content
45
+ end
46
+
47
+ alias_method :cc, :changeful_content
48
+
49
+ private
50
+
51
+ def current_view
52
+ File.basename(File.dirname(__FILE__)) + '/' + File.basename(__FILE__, '.*')
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,12 @@
1
+ require 'active_record'
2
+
3
+ module Changeful
4
+ class Content < ActiveRecord::Base
5
+ self.table_name = :changeful_contents
6
+
7
+ validates :key, :content, :view_type, :file_path, presence: true
8
+ validates :key, uniqueness: { scope: :file_path }
9
+
10
+ scope :all_contents_in, ->(current_view) { where('file_path = ?', current_view) }
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Changeful
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ require 'rails/generators/base'
2
+ require 'rails/generators/active_record'
3
+
4
+ module Changeful
5
+ module Generators
6
+ class InstallGenerator < Rails::Generators::Base # :nodoc:
7
+ include Rails::Generators::Migration
8
+
9
+ def copy_changeful_migration
10
+ migration_template 'migration.rb',
11
+ 'db/migrate/create_changeful_contents.rb'
12
+ end
13
+
14
+ def self.source_root
15
+ File.dirname(__FILE__) + '/templates'
16
+ end
17
+
18
+ def self.next_migration_number(path)
19
+ ActiveRecord::Generators::Base.next_migration_number(path)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ class CreateChangefulContents < ActiveRecord::Migration # :nodoc:
2
+ def change
3
+ create_table :changeful_contents do |t|
4
+ t.string :key
5
+ t.text :content
6
+ t.string :view_type
7
+ t.string :file_path
8
+ t.timestamps null: true
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: changeful
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Wayne Tng
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.0
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
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: generator_spec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: shoulda-matchers
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Changeful is a gem that converts your static content in your views to
98
+ be stored into database. Thereafter, administrator can use RailsAdmin or Active
99
+ Admin to edit the static content.
100
+ email:
101
+ - wayne@futureworkz.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".ruby-gemset"
109
+ - ".ruby-version"
110
+ - ".travis.yml"
111
+ - CODE_OF_CONDUCT.md
112
+ - Gemfile
113
+ - LICENSE.txt
114
+ - README.md
115
+ - Rakefile
116
+ - bin/console
117
+ - bin/setup
118
+ - changeful.gemspec
119
+ - lib/changeful.rb
120
+ - lib/changeful/helpers/view_helpers.rb
121
+ - lib/changeful/models/changeful_content.rb
122
+ - lib/changeful/version.rb
123
+ - lib/generators/changeful/install_generator.rb
124
+ - lib/generators/changeful/templates/migration.rb
125
+ homepage: https://github.com/futureworkz/changeful
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.4.5.1
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Make your static contents editable in database
149
+ test_files: []