sitepress-cli 0.1.21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b6c0e1cd3108fab772a423b7938ddf2016908bd0
4
+ data.tar.gz: bb3d988ace6586506320ceb01aee0bebc9df428a
5
+ SHA512:
6
+ metadata.gz: 5710019297d96327742db57f543a5a6e0ad68e9973ded14d075722f6421b255295422d0c9940161e6f796356365047d3db3195482ad9b940429d0f2c3d738e21
7
+ data.tar.gz: bcee9916813a12ff58137213df58d14d1e066f8d66163769e16f7806d5dd1bbd6df84d0f516a12b328a0fbe3066f6727074b90c7d3ccb281f60190bc7f460b49
@@ -0,0 +1,51 @@
1
+ require "thor"
2
+ require "sitepress-server"
3
+
4
+ module Sitepress
5
+ # Command line interface for compiling Sitepress sites.
6
+ class CLI < Thor
7
+ include Thor::Actions
8
+
9
+ source_root File.expand_path("../../../templates/default", __FILE__)
10
+
11
+ option :config_file, default: Project::DEFAULT_CONFIG_FILE, aliases: :c
12
+ option :bind_address, default: PreviewServer::DEFAULT_BIND_ADDRESS, aliases: :a
13
+ option :port, default: PreviewServer::DEFAULT_PORT, aliases: :p, type: :numeric
14
+ desc "server", "Run preview server"
15
+ def server
16
+ PreviewServer.new(project: project).run port: options.fetch("port"),
17
+ bind_address: options.fetch("bind_address")
18
+ end
19
+
20
+ option :config_file, default: Project::DEFAULT_CONFIG_FILE, aliases: :c
21
+ option :output_path, default: "./build"
22
+ desc "compile", "Compile project into static pages"
23
+ def compile
24
+ project.compiler.compile target_path: options.fetch("output_path")
25
+ end
26
+
27
+ option :config_file, default: Project::DEFAULT_CONFIG_FILE, aliases: :c
28
+ desc "console", "Interactive project shell"
29
+ def console
30
+ REPL.new(context: project).start
31
+ end
32
+
33
+ desc "new PATH", "Create new project at PATH"
34
+ def new(target)
35
+ inside target do
36
+ directory self.class.source_root, "."
37
+ run "bundle install"
38
+ end
39
+ end
40
+
41
+ desc "version", "Show version"
42
+ def version
43
+ say "Sitepress #{Sitepress::VERSION}"
44
+ end
45
+
46
+ private
47
+ def project
48
+ @_project ||= Sitepress::Project.new config_file: options.fetch("config_file")
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,39 @@
1
+ require "pathname"
2
+ require "fileutils"
3
+
4
+ module Sitepress
5
+ # Compile all resources from a Sitepress site into static pages.
6
+ class Compiler
7
+ include FileUtils
8
+
9
+ def initialize(site: )
10
+ @site = site
11
+ end
12
+
13
+ # Iterates through all pages and writes them to disk
14
+ def compile(target_path:)
15
+ target_path = Pathname.new(target_path)
16
+ # TODO: Should file operations go here? Probably not.
17
+ mkdir_p target_path
18
+ root = Pathname.new("/")
19
+ puts "Compiling #{@site.root_path.expand_path}"
20
+ @site.resources.each do |resource|
21
+ # These are root `resource.request_path`
22
+ derooted = Pathname.new(resource.request_path).relative_path_from(root)
23
+ path = target_path.join(derooted)
24
+ mkdir_p path.dirname
25
+ puts " #{path}"
26
+ File.open(path.expand_path, "w"){ |f| f.write render(resource) }
27
+ end
28
+ puts "Successful compilation to #{target_path.expand_path}"
29
+ end
30
+
31
+ private
32
+ def render(resource)
33
+ # TODO: Lets slim this down a bit.
34
+ helpers = HelperLoader.new paths: Dir.glob(@site.root_path.join("helpers/**.rb"))
35
+ context = helpers.context(locals: { current_page: resource, site: @site })
36
+ ResourceRenderer.new(resource: resource).render(context: context)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,32 @@
1
+ require "rack"
2
+
3
+ module Sitepress
4
+ # Evaluates a configuration file on each site request, then delegates to
5
+ # a sitepres server for rednering. In a production environment, you'd want
6
+ # to run `Sitepress::Server` directly.
7
+ class PreviewServer
8
+ DEFAULT_PORT = 8080
9
+ DEFAULT_BIND_ADDRESS = "0.0.0.0".freeze
10
+
11
+ def initialize(project:)
12
+ @project = project
13
+ end
14
+
15
+ def run(port: DEFAULT_PORT, bind_address: DEFAULT_BIND_ADDRESS)
16
+ # TODO: Move all of this junk into the PreviewServer class. Move
17
+ # what's in there now into PreviewServer::Rack
18
+ Rack::Handler::WEBrick.run rack_app,
19
+ BindAddress: bind_address,
20
+ Port: port do |server|
21
+ Signal.trap "SIGINT" do
22
+ server.stop
23
+ end
24
+ end
25
+ end
26
+
27
+ private
28
+ def rack_app
29
+ Proc.new { |env| @project.server.call(env) }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,45 @@
1
+ require "pathname"
2
+ require "forwardable"
3
+
4
+ module Sitepress
5
+ # Configures a site server, compiler, etc from a single configuration
6
+ # file. Useful for static sites or anything that's running outside of
7
+ # a framework like Rails.
8
+ class Project
9
+ # Default path of project configuration file.
10
+ DEFAULT_CONFIG_FILE = "site.rb".freeze
11
+
12
+ attr_reader :site
13
+
14
+ def initialize(config_file: DEFAULT_CONFIG_FILE)
15
+ @config_file = config_file
16
+ end
17
+
18
+ def compiler
19
+ Compiler.new(site: site)
20
+ end
21
+
22
+ def server
23
+ Server.new(site: site)
24
+ end
25
+
26
+ def site
27
+ ConfigurationFile.new(path: @config_file).parse
28
+ end
29
+ end
30
+
31
+ # Evaluates a configuration file to configure a site.
32
+ class ConfigurationFile
33
+ Context = Struct.new(:site)
34
+
35
+ def initialize(path: Project::DEFAULT_CONFIG_FILE)
36
+ @path = Pathname.new(path)
37
+ end
38
+
39
+ def parse(site: Sitepress::Site.new)
40
+ site.tap do |s|
41
+ Context.new(s).instance_eval File.read(@path), @path.to_s
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,23 @@
1
+ require "fileutils"
2
+
3
+ module Sitepress
4
+ # Creates new projects from a template.
5
+ class ProjectTemplate
6
+ DEFAULT_TEMPLATE = File.expand_path("../../../templates/default",__FILE__).freeze
7
+
8
+ include FileUtils
9
+
10
+ def initialize(path: DEFAULT_TEMPLATE)
11
+ @path = path
12
+ end
13
+
14
+ def copy(to:)
15
+ cp_r @path, to
16
+ end
17
+
18
+ def bundle
19
+ Dir.chdir @path do
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ require "irb"
2
+
3
+ module Sitepress
4
+ # Interactive REPL for Sitepress project
5
+ class REPL
6
+ def initialize(context:)
7
+ @context = context
8
+ end
9
+
10
+ # Start interactive REPL.
11
+ def start
12
+ IRB.setup nil
13
+ IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
14
+ require 'irb/ext/multi-irb'
15
+ IRB.irb nil, @context
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ require "sitepress-core"
2
+
3
+ module Sitepress
4
+ autoload :CLI, "sitepress/cli"
5
+ autoload :Compiler, "sitepress/compiler"
6
+ autoload :PreviewServer, "sitepress/preview_server"
7
+ autoload :Project, "sitepress/project"
8
+ autoload :ProjectTemplate, "sitepress/project_template"
9
+ autoload :REPL, "sitepress/repl"
10
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require File.expand_path('../../sitepress/lib/sitepress/version', __FILE__)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sitepress-cli"
8
+ spec.version = Sitepress::VERSION
9
+ spec.authors = ["Brad Gessler"]
10
+ spec.email = ["bradgessler@gmail.com"]
11
+
12
+ spec.summary = %q{Sitepress command line interface and compilation tools for static site.}
13
+ spec.homepage = "https://github.com/sitepress/sitepress"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "sitepress-server", spec.version
21
+ spec.add_runtime_dependency "thor", "~> 0.19.0"
22
+ spec.add_runtime_dependency "rack", ">= 1.0"
23
+ end
@@ -0,0 +1 @@
1
+ build
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "sitepress-cli"
4
+ gem "haml"
5
+ gem "sass"
@@ -0,0 +1,2 @@
1
+ # module PageHelpers
2
+ # end
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <title>Welcome to Sitepress</title>
6
+ <link href='/stylesheets/site.css' rel='stylesheet' type='text/css'>
7
+ </head>
8
+ <body>
9
+ <%= yield %>
10
+ </body>
11
+ </html>
@@ -0,0 +1,3 @@
1
+ <h1>Welcome to Sitepress<h1>
2
+
3
+ <p>Check out the <a href="https://sitepress.cc">Sitepress website</a> for help on getting started and documentation</p>
@@ -0,0 +1,4 @@
1
+ # Default layout for Sitepress pages
2
+ site.manipulate do |resource|
3
+ resource.data["layout"] = "layouts/layout.html.erb" if resource.mime_type == "text/html"
4
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sitepress-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.21
5
+ platform: ruby
6
+ authors:
7
+ - Brad Gessler
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sitepress-server
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.21
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.21
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.19.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.19.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description:
56
+ email:
57
+ - bradgessler@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/sitepress-cli.rb
63
+ - lib/sitepress/cli.rb
64
+ - lib/sitepress/compiler.rb
65
+ - lib/sitepress/preview_server.rb
66
+ - lib/sitepress/project.rb
67
+ - lib/sitepress/project_template.rb
68
+ - lib/sitepress/repl.rb
69
+ - sitepress-cli.gemspec
70
+ - templates/default/.gitignore
71
+ - templates/default/Gemfile
72
+ - templates/default/helpers/page_helpers.rb
73
+ - templates/default/layouts/layout.html.erb
74
+ - templates/default/pages/index.html.erb
75
+ - templates/default/site.rb
76
+ homepage: https://github.com/sitepress/sitepress
77
+ licenses: []
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.5.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Sitepress command line interface and compilation tools for static site.
99
+ test_files: []
100
+ has_rdoc: