5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 10:06:23 +00:00

un poco de overhaul y listar sitios

This commit is contained in:
f 2017-09-28 17:20:31 -03:00
parent 0c05a8123b
commit 3ac158cc93
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
9 changed files with 99 additions and 20 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
vendor/ vendor/
node_modules/ node_modules/
.sass-cache/ .sass-cache/
_sites/

1
_config.yml Normal file
View file

@ -0,0 +1 @@
sites_dir: '_sites'

0
_sites/.keep Normal file
View file

View file

@ -1,25 +1,31 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'rack-flash' require 'yaml'
require 'sinatra/base' require_relative 'sutty/models/jekyll'
require 'sinatra_warden'
require_relative 'sutty/login'
# Sutty
module Sutty module Sutty
# Sutty
class App < Sinatra::Base
use Rack::Flash
use Sutty::Login
register Sinatra::Warden
set :root, File.expand_path(File.join(File.dirname(__FILE__), '..')) # La raíz
def self.root
@root ||= File.expand_path(File.join(File.dirname(__FILE__), '..'))
end
before do # La configuración
authorize! '/login' def self.settings
end @settings ||= YAML.load(File.read(Sutty.config_file))
end
get '/' do def self.config_file
haml :index @config_file ||= File.join(Sutty.root, '_config.yml')
end end
def self.sites_dir
@sites_dir ||= File.join(Sutty.root, Sutty.settings['sites_dir'])
end
def self.sites
binding.pry
@sites ||= Jekyll.all
end end
end end

26
lib/sutty/app.rb Normal file
View file

@ -0,0 +1,26 @@
# frozen_string_literal: true
require 'rack-flash'
require 'sinatra/base'
require 'sinatra_warden'
require_relative 'login'
require_relative '../sutty'
module Sutty
# Sutty
class App < Sinatra::Base
use Rack::Flash
use Sutty::Login
register Sinatra::Warden
set :root, Sutty.root
before do
authorize! '/login'
end
get '/' do
haml :index
end
end
end

View file

@ -4,12 +4,15 @@ require 'net/imap'
require 'rack-flash' require 'rack-flash'
require 'sinatra/base' require 'sinatra/base'
require 'sinatra_warden' require 'sinatra_warden'
require_relative '../sutty'
require_relative '../warden/imap' require_relative '../warden/imap'
require_relative 'models/usuaria' require_relative 'models/usuaria'
module Sutty module Sutty
# Login # Login
class Login < Sinatra::Base class Login < Sinatra::Base
set :root, Sutty.root
use Rack::Flash use Rack::Flash
register Sinatra::Warden register Sinatra::Warden
@ -32,8 +35,6 @@ module Sutty
config.failure_app = self config.failure_app = self
end end
set :root, File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
before do before do
@has_cover = true @has_cover = true
end end

View file

@ -0,0 +1,39 @@
# frozen_string_literal: true
module Sutty
# Un sitio jekyll
class Jekyll
# Devuelve todos los sitios dentro de sites_dir como instancias de
# Jekyll
def self.all
Dir.entries(Sutty.sites_dir).map do |j|
# no queremos . ni .. ni archivos ocultos
next if j.start_with? '.'
_j = File.realpath(File.join(Sutty.sites_dir, j))
next unless Jekyll.is_jekyll? _j
Jekyll.new(_j, j)
end.compact
end
# Comprueba que el directorio parezca ser de jekyll
def self.is_jekyll?(dir)
File.directory?(dir) && File.exists?(File.join(dir, '_config.yml'))
end
def initialize(dir, name = nil)
@root = dir
@name = name if name
end
def config
@config ||= YAML.load(File.read(File.join(@root, '_config.yml')))
end
def name
@name ||= File.basename(@root)
end
end
end

View file

@ -1,4 +1,4 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'pry' unless ENV['RACK_ENV'] == 'production' require 'pry' unless ENV['RACK_ENV'] == 'production'
require_relative 'lib/sutty' require_relative 'lib/sutty/app'

View file

@ -1,3 +1,8 @@
%h1 %h1
Hola Hola
= current_user.username
%table.table.table-striped.table-condensed
%tbody
- Sutty.sites.each do |site|
%tr
%td= site.name