bites 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '08b2bf254de35cfc64624abf78f8c97582535214'
4
- data.tar.gz: 9b5d0847c339a8655f4da60188ae9acbbbf3d879
3
+ metadata.gz: cd2276adb966be41561134043767feb48b6a15e1
4
+ data.tar.gz: 9a8d028165a5574bf097ab464db000a1a02cf5a3
5
5
  SHA512:
6
- metadata.gz: cb8ebd85ee6d3892541655c11bf7c17cb8f8bc9b0c1a8ead8fbc40816fca3e4736ffd79eba7e2d90aaf2fc4e3967f9003fd0cf16bd168af3dabda98e00fcefb3
7
- data.tar.gz: 1c890665e94048f89e1fcc4c5897c3db331eabfb856ec56ddffe221c9202499533dea6d291c64e1e1f414c54a14e2b8a12cdef7ed8114db973f068412988fa81
6
+ metadata.gz: 05323ca2ed434efee8432f0886516dbb6f8f1159c8d9396aed7834ca6da204df71a2c53135ab8a0f4a846524a13decee4ab0ec83456eb6a01a24b9921f1a3c8b
7
+ data.tar.gz: 6ef0b65196990c087e34eed761bcf3f2a823bc9c59875463c31fe09d8c684b147e2284775ffb280149c0e66807f47fdc9e8bb66a771656a991934670e29c4691
data/.gitignore CHANGED
@@ -8,5 +8,7 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
 
11
+ .DS_Store
12
+
11
13
  # rspec failure tracking
12
14
  .rspec_status
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Bites
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bites`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ > Content changes shouldn't require PRs.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ Bites are a simple way of allowing anyone with the correct authorization to edit content from right within your webpage. Engineers shouldn't be the only ones capable of making copy changes, clients or non technical teammembers should be equally able.
6
6
 
7
7
  ## Installation
8
8
 
@@ -14,15 +14,44 @@ gem 'bites'
14
14
 
15
15
  And then execute:
16
16
 
17
- $ bundle
17
+ $ bundle install
18
18
 
19
- Or install it yourself as:
19
+ Once you've installed the gem you need to run
20
20
 
21
- $ gem install bites
21
+ $ rails generate bites:install
22
+
23
+ This includes a migration so you will also need to run `rails db:migrate`
22
24
 
23
25
  ## Usage
24
26
 
25
- TODO: Write usage instructions here
27
+ Bites offers a simple template helper that inserts your content into the webpage
28
+
29
+ ```ruby
30
+ <%= text_bite :text_identifier, default: 'This is some default text' %>
31
+ ```
32
+
33
+ All you need to provide is an identifier symbol (e.g. `:homepage_welcome_text`).
34
+ The default text is also used as the initial value.
35
+
36
+ If you want to allow editing of the bite you must include the `Biteable` helper in the associated controller:
37
+
38
+ ```ruby
39
+ class StaticPagesController < ApplicationController
40
+ include Biteable
41
+
42
+ def index
43
+ end
44
+ end
45
+ ```
46
+
47
+ Appending `edit_page=true` as a query param to the URL will enter the page into edit mode (where bites are replaced with text boxes).
48
+
49
+ Edit ability is protected using HTTP simple auth. You must specify a username and password as environment variables:
50
+
51
+ BITES_USERNAME
52
+ BITES_PASSWORD
53
+
54
+ I recommend using something like [dotenv](https://github.com/bkeepers/dotenv) for this.
26
55
 
27
56
  ## Development
28
57
 
@@ -32,7 +61,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
61
 
33
62
  ## Contributing
34
63
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bites. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/daibhin/bites. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
65
 
37
66
  ## License
38
67
 
@@ -40,4 +69,4 @@ The gem is available as open source under the terms of the [MIT License](http://
40
69
 
41
70
  ## Code of Conduct
42
71
 
43
- Everyone interacting in the Bites project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/bites/blob/master/CODE_OF_CONDUCT.md).
72
+ Everyone interacting in the Bites project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/daibhin/bites/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,9 @@
1
+ class BitesController < ::ApplicationController
2
+
3
+ def update
4
+ bite = Bite.find(params[:id])
5
+ bite.update!(text: params[:bite][:text])
6
+ redirect_to :back
7
+ end
8
+
9
+ end
@@ -0,0 +1,2 @@
1
+ class Bite < ApplicationRecord
2
+ end
@@ -3,6 +3,9 @@ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require "bites/version"
5
5
 
6
+ # Building a new version of the gem:
7
+ # gem build bites.gemspec
8
+
6
9
  Gem::Specification.new do |spec|
7
10
  spec.name = "bites"
8
11
  spec.version = Bites::VERSION
@@ -14,7 +17,7 @@ Gem::Specification.new do |spec|
14
17
  spec.license = "MIT"
15
18
 
16
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
- f.match(%r{^(test|spec|features)/})
20
+ f.match(%r{(^(test|spec|features)/|.gem$)})
18
21
  end
19
22
  spec.bindir = "exe"
20
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -23,4 +26,5 @@ Gem::Specification.new do |spec|
23
26
  spec.add_development_dependency "bundler", "~> 1.15"
24
27
  spec.add_development_dependency "rake", "~> 10.0"
25
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "generator_spec"
26
30
  end
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ resources :bites, only: [:update]
3
+ end
@@ -0,0 +1,17 @@
1
+ module Biteable
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ before_filter :authenticate
6
+ end
7
+
8
+ def authenticate
9
+ if request.params[:edit_page]
10
+ authenticate_or_request_with_http_basic('Administration') do |username, password|
11
+ @bite_authentication = username == ENV['BITES_USERNAME'] && password == ENV['BITES_PASSWORD']
12
+ end
13
+ else
14
+ @bite_authentication = false
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  require "bites/version"
2
+ require "bites/engine"
2
3
 
3
4
  module Bites
4
- # Your code goes here...
5
5
  end
@@ -0,0 +1,17 @@
1
+ module BiteHelper
2
+ def text_bite(identifier, options)
3
+ bite = Bite.find_by(identifier: identifier)
4
+ return bite_form(bite) if @bite_authentication
5
+ return Bite.create(identifier: identifier, text: options.default).text if bite.nil?
6
+ return bite.text unless bite.text.blank?
7
+ return options[:default] if options.present?
8
+ end
9
+
10
+ private def bite_form(bite)
11
+ render(
12
+ inline: "<%= form_for bite do |f| %><%= f.text_area :text %><%= f.submit 'Update' %><% end %>",
13
+ locals: { bite: bite }
14
+ )
15
+ end
16
+
17
+ end
@@ -0,0 +1,11 @@
1
+ require 'bites/bite_helper'
2
+
3
+ module Bites
4
+ class Engine < Rails::Engine
5
+ require 'biteable'
6
+
7
+ initializer 'bite.helper' do |app|
8
+ ActionView::Base.send :include, BiteHelper
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Bites
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,23 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ module Bites
5
+ module Generators
6
+ class InstallGenerator < ::Rails::Generators::Base
7
+
8
+ include Rails::Generators::Migration
9
+
10
+ source_root File.expand_path('../templates', __FILE__)
11
+ desc "Add the migrations for Bites"
12
+
13
+ def self.next_migration_number(path)
14
+ next_migration_number = current_migration_number(path) + 1
15
+ ActiveRecord::Migration.next_migration_number(next_migration_number)
16
+ end
17
+
18
+ def copy_migrations
19
+ migration_template("create_bites.rb", "db/migrate/create_bites.rb")
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ class CreateBites < ActiveRecord::Migration
2
+ def up
3
+ create_table :bites do |t|
4
+ t.string :identifier, null: false
5
+ t.text :text, null: false, default: ""
6
+ end
7
+
8
+ add_index :bites, :identifier, unique: true
9
+ end
10
+
11
+ def down
12
+ drop_table :bites
13
+ end
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bites
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Newell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-06 00:00:00.000000000 Z
11
+ date: 2018-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: generator_spec
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'
55
69
  description:
56
70
  email:
57
71
  - d.newell1@outlook.com
@@ -67,11 +81,19 @@ files:
67
81
  - LICENSE.txt
68
82
  - README.md
69
83
  - Rakefile
84
+ - app/controllers/bites_controller.rb
85
+ - app/models/bite.rb
70
86
  - bin/console
71
87
  - bin/setup
72
88
  - bites.gemspec
89
+ - config/routes.rb
90
+ - lib/biteable.rb
73
91
  - lib/bites.rb
92
+ - lib/bites/bite_helper.rb
93
+ - lib/bites/engine.rb
74
94
  - lib/bites/version.rb
95
+ - lib/generators/bites/install/install_generator.rb
96
+ - lib/generators/bites/install/templates/create_bites.rb
75
97
  homepage: https://daibhin.github.io
76
98
  licenses:
77
99
  - MIT