middleman-blog-ui 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +48 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/middleman-blog-ui.rb +12 -0
- data/lib/middleman/blog/ui/api_server.rb +169 -0
- data/lib/middleman/blog/ui/extension.rb +64 -0
- data/lib/middleman/blog/ui/version.rb +7 -0
- data/middleman-blog-ui.gemspec +38 -0
- data/source/admin/drafts.json.erb +6 -0
- data/source/admin/index.html.haml +18 -0
- data/source/admin/published.json.erb +6 -0
- data/source/javascripts/admin/admin.js +25 -0
- data/source/javascripts/admin/api.coffee +94 -0
- data/source/javascripts/admin/components/admin_navbar.js.coffee +49 -0
- data/source/javascripts/admin/components/app.js.coffee +21 -0
- data/source/javascripts/admin/components/autosize_textarea.js.coffee +60 -0
- data/source/javascripts/admin/components/dashboard.js.coffee +8 -0
- data/source/javascripts/admin/components/dashboard_draft_list.js.coffee +19 -0
- data/source/javascripts/admin/components/dashboard_navbar.js.coffee +51 -0
- data/source/javascripts/admin/components/dashboard_published_list.js.coffee +19 -0
- data/source/javascripts/admin/components/editor.js.coffee +24 -0
- data/source/javascripts/admin/components/editor_navbar.js.coffee +63 -0
- data/source/javascripts/admin/components/markdown_preview.js.coffee +9 -0
- data/source/javascripts/admin/components/metadata_editor.js.coffee +25 -0
- data/source/javascripts/admin/marked.min.js +6 -0
- data/source/javascripts/admin/react-bootstrap.min.js +10 -0
- data/source/javascripts/admin/react-bootstrap.min.js.map +1 -0
- data/source/javascripts/admin/reflux.min.js +1 -0
- data/source/javascripts/admin/stores/article.coffee +71 -0
- data/source/javascripts/admin/stores/command.coffee +83 -0
- data/source/javascripts/admin/stores/drafts.coffee +16 -0
- data/source/javascripts/admin/stores/published.coffee +16 -0
- data/source/javascripts/admin/superagent.js +1318 -0
- data/source/stylesheets/admin.css.scss +55 -0
- metadata +186 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cdc55779ae026dbba0b68101c7f99442cbb0c60a
|
4
|
+
data.tar.gz: 2dba91eb73a5dbdb8a58ffae0aa580c5395e161c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d2dafb7bec2a7ca72407955789ce8f10717cc874627049f8368d007c1aeb8e90d98d6681d9093753ebcfebc332d5c1f28badf160c731b0b62217305c16bb69eb
|
7
|
+
data.tar.gz: 74c976a2feb8008e710a4d0ae607eb08840498f18198cd60bb9f6907e119bc1a88dc6429682c62ddd9ea1628078568adf4bc5e78bf9224ccbe993b01d67a2652
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Will Schenk
|
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,48 @@
|
|
1
|
+
# Middleman::Blog::Ui
|
2
|
+
|
3
|
+
This gem is mean to work with an exitisting middleman site, that uses both middleman-blog and middleman-blog-drafts.
|
4
|
+
|
5
|
+
More information on how it works can be found on my blog, at http://willschenk.com/building-a-gui-for-managing-middleman-blogs/
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
|
10
|
+
Given a middleman app with `middleman-blog` and `middleman-blog-drafts` configured:
|
11
|
+
|
12
|
+
1. Add `middleman-blog-ui` in your `Gemfile`.
|
13
|
+
2. Add `activate :blog_ui` in `config.rb`
|
14
|
+
3. Start `middleman server`
|
15
|
+
4. Visit [http://localhost:4567/admin](http://localhost:4567/admin).
|
16
|
+
|
17
|
+
And now you are living in the fabulous world where you can, from your browser:
|
18
|
+
|
19
|
+
- Edit existing drafts and posts
|
20
|
+
- Create new drafts
|
21
|
+
- Publish drafts into posts
|
22
|
+
- Run some basic `git` commands.
|
23
|
+
- Run `middleman build`
|
24
|
+
- Run `middleman deploy`
|
25
|
+
|
26
|
+
## Next steps
|
27
|
+
|
28
|
+
This is mainly a proof of concept, but I'm using it right now to write this post. The app itself needs
|
29
|
+
|
30
|
+
1. A decent UI
|
31
|
+
2. Support for other static generators other than middleman
|
32
|
+
3. A concept of users
|
33
|
+
4. Shared drafts
|
34
|
+
5. Better error handling
|
35
|
+
|
36
|
+
## Development
|
37
|
+
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
39
|
+
|
40
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it ( https://github.com/[my-github-username]/middleman-blog-ui/fork )
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create a new Pull Request
|
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 "middleman/blog/ui"
|
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,12 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'middleman-core'
|
4
|
+
|
5
|
+
::Middleman::Extensions.register(:blog_ui) do
|
6
|
+
module Middleman::Blog::Ui
|
7
|
+
SOURCE_DIR = File.expand_path(File.join('..', '..', 'source'), __FILE__)
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'middleman/blog/ui/extension'
|
11
|
+
::Middleman::Blog::Ui::Extension
|
12
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'sinatra/json'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
module Middleman
|
6
|
+
module Blog
|
7
|
+
module Ui
|
8
|
+
class ApiServer < Sinatra::Base
|
9
|
+
get '/' do
|
10
|
+
"This is the api server"
|
11
|
+
end
|
12
|
+
|
13
|
+
get '/post' do
|
14
|
+
app = load_app
|
15
|
+
|
16
|
+
logger.info "Looking up #{params[:path]}"
|
17
|
+
|
18
|
+
file = app.sitemap.find_resource_by_path params[:path] if params[:path]
|
19
|
+
|
20
|
+
if !file
|
21
|
+
status 404
|
22
|
+
json error: "Unknown path #{params[:path]}"
|
23
|
+
else
|
24
|
+
raw = File.read file.source_file
|
25
|
+
body = raw.gsub( /^---\n.*?---\n*/m, "" ) # Remove the preyaml
|
26
|
+
|
27
|
+
json meta: file.data, content: body
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
post '/post' do
|
32
|
+
payload = params
|
33
|
+
payload = JSON.parse(request.body.read).symbolize_keys unless params[:path]
|
34
|
+
|
35
|
+
logger.info "Saving #{payload[:path]} with #{payload[:meta]}"
|
36
|
+
|
37
|
+
file = load_app.sitemap.find_resource_by_path payload[:path]
|
38
|
+
|
39
|
+
if !file
|
40
|
+
logger.info "Unknown path: #{payload[:path]}"
|
41
|
+
status 404
|
42
|
+
json error: "Unknown path #{payload[:path]}"
|
43
|
+
else
|
44
|
+
File.open( file.source_file, "w" ) do |out|
|
45
|
+
out.puts YAML.dump( payload[:meta] )
|
46
|
+
out.puts "---"
|
47
|
+
out.puts payload[:body]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
json message: "Post saved"
|
52
|
+
end
|
53
|
+
|
54
|
+
post '/images' do
|
55
|
+
|
56
|
+
File.open('/tmp/' + params['file'][:filename], "wb") do |f|
|
57
|
+
f.write(params['file'][:tempfile].read)
|
58
|
+
end
|
59
|
+
|
60
|
+
json message: "Image uploaded"
|
61
|
+
end
|
62
|
+
|
63
|
+
post '/build' do
|
64
|
+
`bundle exec middleman build 2>&1`
|
65
|
+
end
|
66
|
+
|
67
|
+
post '/update' do
|
68
|
+
`git pull origin master 2>&1`
|
69
|
+
end
|
70
|
+
|
71
|
+
post '/status' do
|
72
|
+
`git status 2>&1`
|
73
|
+
end
|
74
|
+
|
75
|
+
post '/drafts' do
|
76
|
+
if !params[:title]
|
77
|
+
status 404
|
78
|
+
json error: "Bad Parameters"
|
79
|
+
else
|
80
|
+
logger.info "Created draft for #{params[:title]}"
|
81
|
+
|
82
|
+
slug = params[:title].downcase.gsub( /[^a-z]/, "-" )
|
83
|
+
|
84
|
+
draft_dir = File.expand_path( "source/drafts", Dir.pwd )
|
85
|
+
FileUtils.mkdir_p draft_dir
|
86
|
+
|
87
|
+
outfile = File.expand_path( "source/drafts/#{slug}.html.markdown", Dir.pwd )
|
88
|
+
|
89
|
+
File.open( outfile, "w" ) do |out|
|
90
|
+
out.puts YAML.dump( params )
|
91
|
+
out.puts "---\n\n# #{params[:title]}\nHere we go!"
|
92
|
+
end
|
93
|
+
|
94
|
+
json created: "drafts/#{slug}.html"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
post '/diff' do
|
99
|
+
payload = params
|
100
|
+
payload = JSON.parse(request.body.read).symbolize_keys unless params[:path]
|
101
|
+
|
102
|
+
file = load_app.sitemap.find_resource_by_path payload[:path]
|
103
|
+
|
104
|
+
if !file
|
105
|
+
logger.info "Unknown path: #{payload[:path]}"
|
106
|
+
status 404
|
107
|
+
"Unknown path #{payload[:path]}"
|
108
|
+
else
|
109
|
+
`git diff #{file.source_file} 2>&1`
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
post '/publish' do
|
115
|
+
payload = params
|
116
|
+
payload = JSON.parse(request.body.read).symbolize_keys unless params[:path]
|
117
|
+
|
118
|
+
file = load_app.sitemap.find_resource_by_path payload[:path]
|
119
|
+
|
120
|
+
if !file
|
121
|
+
logger.info "Unknown path: #{payload[:path]}"
|
122
|
+
status 404
|
123
|
+
"Unknown path #{payload[:path]}"
|
124
|
+
else
|
125
|
+
`bundle exec middleman publish #{file.source_file} 2>&1`
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
post '/deploy' do
|
131
|
+
content_type :txt
|
132
|
+
stream do |out|
|
133
|
+
5.times do
|
134
|
+
out << "Hi there\n"
|
135
|
+
puts "Hi there"
|
136
|
+
sleep 1
|
137
|
+
end
|
138
|
+
end
|
139
|
+
# IO.popen( '/Users/wschenk/src/willschenk.com/longrunning.sh' ) do |io|
|
140
|
+
# stream do |out|
|
141
|
+
# io.each do |s|
|
142
|
+
# puts s
|
143
|
+
# out << s
|
144
|
+
# end
|
145
|
+
# end
|
146
|
+
# end
|
147
|
+
end
|
148
|
+
|
149
|
+
private
|
150
|
+
def load_app
|
151
|
+
opts = {}
|
152
|
+
|
153
|
+
app = ::Middleman::Application.server.inst do
|
154
|
+
set :environment, opts[:environment].to_sym if opts[:environment]
|
155
|
+
|
156
|
+
# ::Middleman::Logger.singleton(opts[:debug] ? 0 : 1, opts[:instrumenting] || false)
|
157
|
+
logger
|
158
|
+
end
|
159
|
+
|
160
|
+
app
|
161
|
+
end
|
162
|
+
|
163
|
+
def logger
|
164
|
+
::Middleman::Logger.singleton( 1 )
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'middleman/blog/ui/api_server'
|
2
|
+
require 'react/source'
|
3
|
+
require 'sprockets/coffee-react'
|
4
|
+
|
5
|
+
module Middleman
|
6
|
+
module Blog
|
7
|
+
module Ui
|
8
|
+
# Middleman extension entry point
|
9
|
+
class Extension < Middleman::Extension
|
10
|
+
def initialize(app, options_hash = {}, &block)
|
11
|
+
super
|
12
|
+
|
13
|
+
puts "== Starting API Server on /api"
|
14
|
+
app.map "/api" do
|
15
|
+
run ApiServer
|
16
|
+
end
|
17
|
+
|
18
|
+
::Sprockets.register_preprocessor 'application/javascript', ::Sprockets::CoffeeReact
|
19
|
+
end
|
20
|
+
|
21
|
+
def after_configuration
|
22
|
+
# p "after_configuration"
|
23
|
+
register_extension_templates
|
24
|
+
Dir.glob( "#{SOURCE_DIR}/javascripts/**/*" ).each do |f|
|
25
|
+
# p "Adding #{f}"
|
26
|
+
app.sprockets.append_path File.dirname(f)
|
27
|
+
end
|
28
|
+
Dir.glob( "#{SOURCE_DIR}/stylesheets/*" ).each do |f|
|
29
|
+
# p "Adding #{f}"
|
30
|
+
app.sprockets.append_path File.dirname(f)
|
31
|
+
end
|
32
|
+
app.sprockets.append_path File.dirname(::React::Source.bundled_path_for('react.js'))
|
33
|
+
end
|
34
|
+
|
35
|
+
def manipulate_resource_list(resources)
|
36
|
+
# p "manipulate_resource_list"
|
37
|
+
Dir.glob( "#{SOURCE_DIR}/**/*" ).each do |path|
|
38
|
+
unless File.directory? path
|
39
|
+
resources << make_template( path, path.gsub( /#{SOURCE_DIR}\//, "" ) )
|
40
|
+
end
|
41
|
+
end
|
42
|
+
# resources << make_template( "#{SOURCE_DIR}/stylesheets/admin.css.scss", "stylesheets/admin.css" )
|
43
|
+
resources
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
def register_extension_templates
|
48
|
+
# We call reload_path to register the templates directory with Middleman.
|
49
|
+
# The path given to app.files must be relative to the Middleman site's root.
|
50
|
+
templates_dir_relative_from_root = Pathname(SOURCE_DIR).relative_path_from(Pathname(app.root))
|
51
|
+
app.files.reload_path(templates_dir_relative_from_root)
|
52
|
+
end
|
53
|
+
|
54
|
+
def make_template( file, name )
|
55
|
+
name = name.gsub( /.erb/, "" ).gsub( /.haml/, "" ).gsub( /.coffee/, "" ).gsub( /.scss/, "" )
|
56
|
+
# puts "Adding #{name}"
|
57
|
+
Middleman::Sitemap::Resource.new(app.sitemap, name, file).tap do |resource|
|
58
|
+
resource.add_metadata(options: { layout: false }, locals: {})
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'middleman/blog/ui/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "middleman-blog-ui"
|
8
|
+
spec.version = Middleman::Blog::Ui::VERSION
|
9
|
+
spec.authors = ["Will Schenk"]
|
10
|
+
spec.email = ["wschenk@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Basic web UI for a middleman-blog.}
|
13
|
+
spec.description = %q{Basic web UI for a middleman-blog.}
|
14
|
+
spec.homepage = "https://github.com/HappyFunCorp/middleman-blog-ui"
|
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'] = "https://rubygems.org"
|
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_dependency "middleman-react"
|
31
|
+
spec.add_dependency "sprockets-coffee-react"
|
32
|
+
spec.add_dependency "sinatra"
|
33
|
+
spec.add_dependency "sinatra-contrib"
|
34
|
+
spec.add_dependency "react-source"
|
35
|
+
spec.add_dependency "bootstrap-sass"
|
36
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
37
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
38
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
!!! 5
|
2
|
+
%html.no-js
|
3
|
+
%head
|
4
|
+
%meta{ :charset => 'utf-8' }/
|
5
|
+
%meta{ 'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1' }/
|
6
|
+
|
7
|
+
%title Blog Admin
|
8
|
+
|
9
|
+
%meta{ :name => 'description', :content => '' }/
|
10
|
+
%meta{ :name => 'viewport', :content => 'width=device-width' }/
|
11
|
+
= stylesheet_link_tag 'admin'
|
12
|
+
= javascript_include_tag 'admin/admin', 'modernizr'
|
13
|
+
|
14
|
+
%body
|
15
|
+
#content
|
16
|
+
:javascript
|
17
|
+
React.render( React.createElement(App, null), document.getElementById('content') );
|
18
|
+
|