Skip to content

Commit

Permalink
Merge pull request #51 from spartansystems/feature/video-and-datepicker
Browse files Browse the repository at this point in the history
Add video files and datepicker field
  • Loading branch information
davidmiller11 authored Dec 9, 2016
2 parents 133bbcd + 16eb9c7 commit 6b687ab
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 63 deletions.
2 changes: 2 additions & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ruby:
config_file: .rubocop.yml
30 changes: 29 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
AllCops:
TargetRubyVersion: 2.3

Style/Documentation:
Enabled: false

Style/DotPosition:
EnforcedStyle: leading
SupportedStyles:
- leading
- trailing

Style/FrozenStringLiteralComment:
EnforcedStyle: when_needed
SupportedStyles:
- when_needed
- always
- never

Style/StringLiterals:
Enabled: false
EnforcedStyle: single_quotes
SupportedStyles:
- single_quotes
- double_quotes
ConsistentQuotesInMultiline: false

Style/StringLiteralsInInterpolation:
EnforcedStyle: single_quotes
SupportedStyles:
- single_quotes
- double_quotes


2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
source 'http://rubygems.org'
source 'https://rubygems.org'
gemspec
90 changes: 46 additions & 44 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
atomic_cms (0.2.2)
atomic_cms (0.2.6)
activeadmin (= 1.0.0.pre2)
atomic_assets (~> 0.1.0)
jquery-rails (~> 4.0, >= 4.0.3)
Expand Down Expand Up @@ -61,43 +61,44 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arbre (1.0.3)
arbre (1.1.1)
activesupport (>= 3.0.0)
arel (6.0.3)
atomic_assets (0.1.0)
draper (~> 2.1)
bourbon (4.2.6)
bourbon (4.2.7)
sass (~> 3.4)
thor (~> 0.19)
builder (3.2.2)
climate_control (0.0.3)
activesupport (>= 3.0)
cocaine (0.5.7)
cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
coffee-rails (4.1.0)
coffee-rails (4.2.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
railties (>= 4.0.0, < 5.2.x)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.9.1.1)
coffee-script-source (1.11.1)
concurrent-ruby (1.0.2)
diff-lcs (1.2.5)
draper (2.1.0)
actionpack (>= 3.0)
activemodel (>= 3.0)
activesupport (>= 3.0)
request_store (~> 1.0)
erubis (2.7.0)
execjs (2.6.0)
execjs (2.7.0)
factory_girl (4.5.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.5.0)
factory_girl (~> 4.5.0)
railties (>= 3.0.0)
formtastic (3.1.3)
formtastic (3.1.4)
actionpack (>= 3.2.13)
formtastic_i18n (0.4.1)
globalid (0.3.6)
formtastic_i18n (0.6.0)
globalid (0.3.7)
activesupport (>= 4.1.0)
has_scope (0.6.0)
actionpack (>= 3.2, < 5)
Expand All @@ -108,33 +109,35 @@ GEM
has_scope (~> 0.6.0.rc)
railties (>= 3.2, < 5)
responders
jquery-rails (4.0.5)
rails-dom-testing (~> 1.0)
jquery-rails (4.2.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (5.0.5)
jquery-ui-rails (6.0.1)
railties (>= 3.2.16)
json (1.8.3)
kaminari (0.16.3)
kaminari (0.17.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.6.2)
mail (2.6.4)
mime-types (>= 1.16, < 4)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mimemagic (0.3.0)
mini_portile (0.6.2)
minitest (5.8.1)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
paperclip (4.3.1)
paperclip (4.3.7)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
cocaine (~> 0.5.5)
mime-types
mimemagic (= 0.3.0)
polyamorous (1.2.0)
polyamorous (1.3.1)
activerecord (>= 3.0)
rack (1.6.4)
rack-test (0.6.3)
Expand Down Expand Up @@ -164,16 +167,16 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
ransack (1.7.0)
ransack (1.8.2)
actionpack (>= 3.0)
activerecord (>= 3.0)
activesupport (>= 3.0)
i18n
polyamorous (~> 1.2)
redcarpet (3.3.3)
request_store (1.2.0)
responders (2.1.0)
railties (>= 4.2.0, < 5)
polyamorous (~> 1.3)
redcarpet (3.3.4)
request_store (1.3.1)
responders (2.3.0)
railties (>= 4.2.0, < 5.1)
rspec-core (3.3.2)
rspec-support (~> 3.3.0)
rspec-expectations (3.3.1)
Expand All @@ -191,35 +194,34 @@ GEM
rspec-mocks (~> 3.3.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
sass (3.4.19)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
sass (3.4.22)
sass-rails (5.0.6)
railties (>= 4.0.0, < 6)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
shoulda-matchers (3.0.0)
activesupport (>= 4.0.0)
slim (3.0.6)
temple (~> 0.7.3)
slim (3.0.7)
temple (~> 0.7.6)
tilt (>= 1.3.3, < 2.1)
slim-rails (3.0.1)
actionmailer (>= 3.1, < 5.0)
actionpack (>= 3.1, < 5.0)
activesupport (>= 3.1, < 5.0)
railties (>= 3.1, < 5.0)
slim-rails (3.1.1)
actionpack (>= 3.1)
railties (>= 3.1)
slim (~> 3.0)
sprockets (3.4.0)
sprockets (3.7.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (2.3.3)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sprockets-rails (3.2.0)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.11)
temple (0.7.6)
temple (0.7.7)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.1)
tilt (2.0.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)

Expand All @@ -238,4 +240,4 @@ DEPENDENCIES
sqlite3

BUNDLED WITH
1.10.6
1.12.5
13 changes: 13 additions & 0 deletions app/assets/javascripts/atomic_cms.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@

page = angular.module('page', ['markdown', 'ngSanitize']);

page.config(function($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist([
'self',
'http://s3.amazonaws.com/**'
]);
});

page.filter('vimeo_url', [
'$sce', function($sce) {
return function(id) {
Expand Down Expand Up @@ -141,6 +148,7 @@
$editor.find(':file').each(function() {
var $input = $(this);
var $next = $($input.siblings('input'));
var $errors = $($input.siblings('div.errors'));
$input.attr('name', null).val('');

$input.on('change', function(event) {
Expand All @@ -159,6 +167,11 @@
var parsed = JSON.parse(data);
$next.val(parsed.url);
$next.change();
$errors.empty();
},
error: function (response) {
var data = JSON.parse(response.responseText);
$errors.text(data.errors.file[0]);
}
});
});
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/atomic_cms/media_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ def create
if asset.save
render json: { url: asset.url }.to_json, status: :created
else
render json: {}.to_json, status: :unprocessable_entity
render json: { errors: asset.errors }.to_json,
status: :unprocessable_entity
end
end

Expand Down
10 changes: 7 additions & 3 deletions app/controllers/concerns/media_scrubber.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class MediaScrubber
attr_accessor :original, :filtered
attr_accessor :original, :filtered, :errors

def initialize(args)
@original = args.fetch(:file, nil)
Expand All @@ -8,12 +8,16 @@ def initialize(args)

def infer_media_type
return nil unless original.respond_to?(:content_type)
AtomicCms::Image.new(file: original) if original.content_type.match(/image/)
params = { file: original }
return AtomicCms::Image.new(params) if original.content_type =~ /image/
AtomicCms::Video.new(params) if original.content_type =~ /video/
end

def valid?
return false unless filtered
filtered.valid?
return true if filtered.valid?
@errors = filtered.errors
false
end

def save
Expand Down
7 changes: 7 additions & 0 deletions app/models/atomic_cms/video.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true
module AtomicCms
class Video < Media
validates_attachment :file, presence: true,
content_type: { content_type: /\Avideo/ }
end
end
3 changes: 3 additions & 0 deletions app/views/components/_datepicker_field.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
span.li.string.input
label.label #{name.to_s.humanize}
input.cms-field.datepicker type="text" name="#{name}" value="#{value}" data-ng-model="preview.#{name}"
1 change: 1 addition & 0 deletions app/views/components/_file_field.slim
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ span.li.string.input
label.label #{name.to_s.humanize}
input.cms-field type="file"
label.label.filler #{name.to_s.humanize}
.errors
input.cms-field type="text" name="#{name}" data-ng-model="preview.#{name}" value="#{value}"
4 changes: 2 additions & 2 deletions atomic_cms.gemspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Gem::Specification.new do |s|
s.name = 'atomic_cms'
s.version = '0.2.5'
s.version = '0.3.0'
s.summary = 'Atomic CMS'
s.description = 'Live CMS powered by atomic assets.'
s.authors = ['Don Humphreys', 'Spartan']
s.email = '[email protected]'
s.files = `git ls-files`.split(/\n/)
s.test_files = Dir['spec/**/*']
s.homepage = 'https://github.com/spartansystems/atomic_cms'
s.license = 'MIT'
s.license = 'MIT'

s.add_dependency 'rails', '~> 4.2'
s.add_dependency 'activeadmin', '1.0.0.pre2'
Expand Down
18 changes: 10 additions & 8 deletions spec/controllers/media_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "rails_helper"
# frozen_string_literal: true
require 'rails_helper'

RSpec.describe AtomicCms::MediaController, type: :controller do
# Previously the engines guide contained an incorrect example that
Expand All @@ -8,23 +9,24 @@
# in the test case with `Foo::Engine.routes`.
before { @routes = AtomicCms::Engine.routes }

it "accepts a post request and fails with bad data" do
scrubber = double("scrubber")
it 'accepts a post request and fails with bad data' do
scrubber = double('scrubber')
allow(MediaScrubber).to receive(:new).and_return(scrubber)
allow(scrubber).to receive(:save).and_return(false)
allow(scrubber).to receive(:errors)

post :create, file: double("file")
post :create, file: double('file')

expect(response).to have_http_status(:unprocessable_entity)
end

it "accepts a post with an image" do
scrubber = double("scrubber", save: true, url: "http://www.google.com")
it 'accepts a post with a file' do
scrubber = double('scrubber', save: true, url: 'http://www.google.com')
expect(MediaScrubber).to receive(:new).and_return(scrubber)

post :create, file: double("file")
post :create, file: double('file')

expect(response).to have_http_status(:created)
expect(response.body).to include("http://www.google.com")
expect(response.body).to include('http://www.google.com')
end
end
Loading

0 comments on commit 6b687ab

Please sign in to comment.