docks_app 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzU4M2JmNDY3NjNkZWVjZWNmN2MxYTZiMjE4MWFiNzM4MjU0MWY0Nw==
4
+ MTZkNGY3ZjlkOTJlNTA4OGUwOWNhNzA0OWZmNjdjYjQ5ZDc5YjgzYg==
5
5
  data.tar.gz: !binary |-
6
- ZDgwZDQ4MWYyM2I5ZGRkNDQ5YzQ2Y2IyZmNjMGRmM2NlN2E0MGQ3NA==
6
+ OWRlMjYyMDllNzM3YTdlMjI2ZjhjMWIzOGE4ZDA4YjliMGZmYTJiOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OGE5OWJiOGQxZDFiZDM4Y2FlOWU4ZmZlNTQzOTk4YjY2MGUzNzNjZTBiMDM2
10
- MjQ1OWE4NDM2OTFlNmIwZDI2YWRiM2MxMjg4OWJjMDJlNDQzNDIwNzIzZTNk
11
- ZjRhMmRlZWFkNDk2OTcxYWMwNmE5ZjU3MDliNTU0YWU1NzAyOGE=
9
+ MTk0NTk4YWQ1NDM2ODU2OTlkNmVlM2Q1MmM0MzExYTRkNDAxZTZlOTgwZDlh
10
+ OWY0YjdjNzAwOWFjODgzMzM4MDJiYjc5MDJhYWMyOTAwMTZjZWUyYTcxZTdm
11
+ MDBjNTQ4YmI1ZTAwM2IzZWY3YTZmOThlNjUwODA2YzhiYzVlMGQ=
12
12
  data.tar.gz: !binary |-
13
- OTdhYjU4NDgyNDI3NTM3Y2IxMmVlZjY2OTQyNjZjZjg4YWI2OGJmZTc1NTdj
14
- M2ExN2M3Y2Q0ZGJhYTc3NDczMWRkZmYwODZiMDUwMTY1ZWI5ZTkxZDhjMTZh
15
- MjAxYzJjODMzZmUyNjI1YTJiOWE0MjQ5NGZmZTM4MmQ4NGI1MmY=
13
+ MGRlNjcwZjZlZWU3ZDFjNzIxNzNkYTVkYWUzOTk1MzU3YjlmNzQ3ZDk3MzVh
14
+ NmI5NTlkNjI4MjhmOWMwY2I5OTUzYmUwOTJhZDJlNjkyNjY5ZDZjOWM5ZTRi
15
+ ZWQ4ZTQwM2JhMmEwODBlZWMzYzRkNDg3NGRiNTViNTVjMzc4YzY=
@@ -25,8 +25,6 @@
25
25
  // all pattern files will be nested inside this directory.
26
26
  "mount_at": {{{mount_at}}},
27
27
 
28
- "use_theme_assets": {{{use_theme_assets}}},
29
-
30
28
  // The name of the Github repo for this project. This can either be the URL or
31
29
  // in the form `<username>/<repo>`. The default theme uses this option, if
32
30
  // passed, to provide links to create issue and view source for your pattern
@@ -26,8 +26,6 @@ Docks.configure do |config|
26
26
  # all pattern files will be nested inside this directory.
27
27
  config.mount_at = {{{mount_at}}}
28
28
 
29
- config.use_theme_assets = {{{use_theme_assets}}}
30
-
31
29
  # The name of the Github repo for this project. This can either be the URL or
32
30
  # in the form `<username>/<repo>`. The default theme uses this option, if
33
31
  # passed, to provide links to create issue and view source for your pattern
@@ -25,8 +25,6 @@ templates: {{{templates}}}
25
25
  # all pattern files will be nested inside this directory.
26
26
  mount_at: {{{mount_at}}}
27
27
 
28
- use_theme_assets: {{{use_theme_assets}}}
29
-
30
28
  # The name of the Github repo for this project. This can either be the URL or
31
29
  # in the form `<username>/<repo>`. The default theme uses this option, if
32
30
  # passed, to provide links to create issue and view source for your pattern
@@ -20,7 +20,7 @@ module Docks
20
20
  def method_missing(meth)
21
21
  if options.respond_to?(meth)
22
22
  present(options.send(meth), meth)
23
- elsif (result = default_config.instance_variable_get("@#{meth}".to_sym))
23
+ elsif !(result = default_config.instance_variable_get("@#{meth}".to_sym)).nil?
24
24
  present(result, meth)
25
25
  else
26
26
  super
@@ -104,10 +104,15 @@ module Docks
104
104
  end
105
105
 
106
106
  def self.setup(options)
107
- @options = OpenStruct.new(options)
107
+ @options = options = OpenStruct.new(options)
108
108
  @assets_dir = File.join(Dir.pwd, Docks::ASSETS_DIR)
109
109
  FileUtils.mkdir_p(@assets_dir)
110
110
 
111
+ if options.theme
112
+ theme = Themes.for(options.theme)
113
+ theme.configure(Docks.config) if theme && theme.respond_to?(:configure)
114
+ end
115
+
111
116
  if Dir[CONFIG_FILE].empty?
112
117
  setup_config
113
118
  end
@@ -16,8 +16,7 @@ module Docks
16
16
  :sources,
17
17
  :destination,
18
18
  :cache_location,
19
- :templates,
20
- :helpers
19
+ :templates
21
20
  ]
22
21
 
23
22
  # Key details — these are required
@@ -28,7 +27,7 @@ module Docks
28
27
 
29
28
  # Random assortment of other stuff
30
29
  attr_accessor :github_repo, :mount_at, :helpers, :compiled_assets,
31
- :naming_convention, :pattern_id, :paginate, :use_theme_assets
30
+ :naming_convention, :pattern_id, :paginate
32
31
 
33
32
  # Stateful stuff
34
33
  attr_reader :configured
@@ -68,6 +67,10 @@ module Docks
68
67
  !!@paginate
69
68
  end
70
69
 
70
+ def has_theme?
71
+ !!@theme
72
+ end
73
+
71
74
  def pattern_id(*args)
72
75
  Docks.pattern_id(*args)
73
76
  end
@@ -104,6 +107,16 @@ module Docks
104
107
  yield Parser
105
108
  end
106
109
 
110
+ def helpers
111
+ @helpers.map do |helper|
112
+ if helper.kind_of?(String)
113
+ make_path_absolute(helper)
114
+ else
115
+ helper
116
+ end
117
+ end
118
+ end
119
+
107
120
  ROOT_DEPENDENT_PATHS.each do |path|
108
121
  define_method(path) do
109
122
  paths = instance_variable_get("@#{path.to_s}".to_sym)
@@ -125,12 +138,11 @@ module Docks
125
138
  ]
126
139
  @compiled_assets = []
127
140
  @github_repo = ""
128
- @paginate = :pattern
129
141
  @naming_convention = NamingConventions::BEM.instance
130
142
  @helpers = []
131
143
 
132
- @theme = Themes.for("API")
133
- @use_theme_assets = true
144
+ @theme = false
145
+ @paginate = false
134
146
 
135
147
  @root = Pathname.pwd
136
148
  @cache_location = ".#{Docks::Cache::DIR}"
@@ -186,7 +198,7 @@ module Docks
186
198
  end
187
199
 
188
200
  if File.extname(configurer) =~ /rb/
189
- self.class_eval(File.read(configurer))
201
+ self.class_eval(File.read(configurer), configurer, 0)
190
202
  else
191
203
  Languages.register_bundled_languages
192
204
  language = Languages.language_for(configurer)
@@ -8,6 +8,7 @@ module Docks
8
8
  return unless renderer.respond_to?(:helpers)
9
9
 
10
10
  renderer.helpers(*bundled_helpers)
11
+ renderer.helpers(*Docks.config.theme.helpers) if Docks.config.has_theme?
11
12
  renderer.helpers(*Docks.config.helpers)
12
13
  renderer
13
14
  end
@@ -34,13 +34,13 @@ module Docks
34
34
  end
35
35
 
36
36
  def docks_stylesheet(stylesheet = :main)
37
- return unless Docks.config.use_theme_assets
37
+ return unless Docks.config.has_theme?
38
38
  postfix = (stylesheet.to_sym == :main ? "" : "-#{stylesheet.to_s}")
39
39
  stylesheet_link_tag("docks#{postfix}.css")
40
40
  end
41
41
 
42
42
  def docks_javascript(script = :main)
43
- return unless Docks.config.use_theme_assets
43
+ return unless Docks.config.has_theme?
44
44
  postfix = (script.to_sym == :main ? "" : "_#{script.to_s}")
45
45
  javascript_include_tag("docks#{postfix}.js")
46
46
  end
@@ -58,29 +58,16 @@ module Docks
58
58
  end
59
59
 
60
60
  def render_description(description, options = {})
61
- @example_count ||= 0
62
61
  description.gsub! /(href\s*=\s*['"])@link\s([^'"]*)(.)/ do |match|
63
62
  "#{$1}#{docks_path($2, options)}#{$3}"
64
63
  end
65
64
 
66
- render(layout: false, inline: description.gsub(/<fenced_code_block[^>]*>(.*?)<\/fenced_code_block>/m) { |match|
67
- @example_count += 1
68
- code = $1.dup
69
- has_demo = match.include?("data-has-demo")
70
- language = match.match(/data\-language=["']([^'"]*)/).captures.first
71
-
72
- code_details = []
73
- code_details << { code: code, language: language, label: "Helper" }
74
-
75
- if has_demo
76
- code_details << { code: render(inline: code, layout: false), language: "html", label: "Markup" }
77
- end
65
+ render(layout: false, inline: render_description_with_theme(description, options))
66
+ end
78
67
 
79
- docks_code_block code: code_details,
80
- hideable?: has_demo,
81
- id: "code-block--example-#{@example_count}",
82
- demo?: has_demo
83
- })
68
+ # To be (optionally) overriden in themes
69
+ def render_description_with_theme(description, options = {})
70
+ description
84
71
  end
85
72
  end
86
73
  end
@@ -9,7 +9,7 @@ module Docks
9
9
  if helper.kind_of?(Module)
10
10
  self.send(:extend, helper)
11
11
  elsif File.exists?(helper)
12
- load_helpers.module_eval(File.read(helper))
12
+ load_helpers.module_eval(File.read(helper), helper, 0)
13
13
  end
14
14
  end
15
15
 
@@ -1,3 +1,3 @@
1
1
  module Docks
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -69,6 +69,13 @@ describe Docks::Builder do
69
69
  expect(File.read(copied_file)).to eq "# foo"
70
70
  end
71
71
 
72
+ it "preconfigures with the specified theme" do
73
+ default_options[:theme] = "API"
74
+ subject.setup(default_options)
75
+ expect(Docks.config.theme).to be_a Docks::Themes::API
76
+ expect(Docks.config.paginate).to eq "pattern"
77
+ end
78
+
72
79
  it "configures the pattern library with the new config file" do
73
80
  expect(Docks).to receive(:configure).with no_args
74
81
  subject.setup(default_options)
@@ -183,7 +190,7 @@ describe Docks::Builder do
183
190
 
184
191
  describe ".parse" do
185
192
  before :each do
186
- Docks.configure_with(root: empty_dir, library_assets: "")
193
+ Docks.configure_with(root: empty_dir)
187
194
  end
188
195
 
189
196
  it "adds the parse function to the top-level Docks namespace" do
@@ -228,7 +235,7 @@ describe Docks::Builder do
228
235
  FileUtils.mkdir_p(existing_dir)
229
236
  FileUtils.cd(existing_dir)
230
237
  Docks::Templates.send(:clean)
231
- Docks.configure_with(destination: destination, root: existing_dir)
238
+ Docks.configure_with(destination: destination, root: existing_dir, theme: "API", paginate: "pattern")
232
239
 
233
240
  default_options[:script_language] = "coffeescript"
234
241
  subject.setup(default_options)
@@ -49,8 +49,7 @@ describe Docks::Configuration do
49
49
  expect(subject.templates).to eq subject.root + "#{Docks::ASSETS_DIR}/templates"
50
50
  expect(subject.asset_folders).to eq OpenStruct.new(styles: "styles", scripts: "scripts")
51
51
  expect(subject.mount_at).to eq "pattern-library"
52
- expect(subject.theme).to eq Docks::Themes::API.instance
53
- expect(subject.use_theme_assets).to be true
52
+ expect(subject.theme).to be false
54
53
  end
55
54
 
56
55
  describe "#root=" do
@@ -11,6 +11,7 @@ describe Docks::Helpers::Path do
11
11
  before(:each) do
12
12
  Docks::Languages.register_bundled_languages
13
13
  Docks.current_render_destination = Docks.config.destination + "baz/index.html"
14
+ Docks.configure_with(theme: "API")
14
15
  subject.instance_variable_set(:@pattern_library, pattern_library)
15
16
  subject.instance_variable_set(:@pattern, pattern)
16
17
  end
@@ -178,8 +179,8 @@ describe Docks::Helpers::Path do
178
179
  expect(subject.docks_stylesheet(:demo)).to eq subject.stylesheet_link_tag("docks-demo.css")
179
180
  end
180
181
 
181
- it "returns nothing when config.use_theme_assets is false" do
182
- Docks.configure_with(use_theme_assets: false)
182
+ it "returns nothing when there is no theme" do
183
+ Docks.configure_with(theme: false)
183
184
  expect(subject.docks_stylesheet).to be nil
184
185
  end
185
186
  end
@@ -193,8 +194,8 @@ describe Docks::Helpers::Path do
193
194
  expect(subject.docks_javascript(:demo)).to eq subject.javascript_include_tag("docks_demo.js")
194
195
  end
195
196
 
196
- it "returns nothing when config.use_theme_assets is false" do
197
- Docks.configure_with(use_theme_assets: false)
197
+ it "returns nothing when there is no theme" do
198
+ Docks.configure_with(theme: false)
198
199
  expect(subject.docks_javascript).to be nil
199
200
  end
200
201
  end
@@ -102,57 +102,12 @@ describe Docks::Helpers::Render do
102
102
  expect(pattern.description).to eq "foo bar <a href='/pattern-library/baz'>baz</a>"
103
103
  end
104
104
 
105
- context "when there is a code block" do
106
- before(:each) do
107
- allow(subject).to receive(:render) { |opts| opts[:inline] }
108
- end
109
-
110
- let(:code_block) { "<div>\n Foo\n</div>" }
111
- let(:language) { "html" }
112
- let(:markdown) { Redcarpet::Markdown.new(Docks::Markdown::Renderer, fenced_code_blocks: true) }
113
-
114
- it "renders a code block" do
115
- pattern.description = markdown.render(markdown_code_block)
116
- expect(subject).to receive(:docks_code_block) do |options|
117
- expect(options[:hideable?]).to be false
118
- expect(options[:demo?]).to be false
119
-
120
- code = options[:code]
121
- expect(code.length).to be 1
122
- expect(code.first[:code].strip).to eq code_block
123
- expect(code.first[:language]).to eq language
124
- end
125
-
126
- subject.render_everything
127
- end
128
-
129
- it "renders a code block with the a demo" do
130
- pattern.description = markdown.render(markdown_code_block(with_demo: true))
131
- expect(subject).to receive(:docks_code_block) do |options|
132
- expect(options[:hideable?]).to be true
133
- expect(options[:demo?]).to be true
134
- end
135
-
136
- subject.render_everything
137
- end
138
-
139
- it "adds a unique ID to each demo" do
140
- pattern.description = markdown.render(markdown_code_block * 2)
141
-
142
- ids = []
143
- expect(subject).to receive(:docks_code_block).twice do |options|
144
- ids.push(options[:id])
145
- end
146
-
147
- subject.render_everything
148
- expect(ids).to eq ids.uniq
149
- end
150
-
151
- private
152
-
153
- def markdown_code_block(options = {})
154
- options.fetch(:with_demo, false) ? "```#{language}_demo\n#{code_block}\n```" : "```#{language}\n#{code_block}\n```\n"
155
- end
105
+ it "calls the theme's render description helper" do
106
+ allow(subject).to receive(:render) { |opts| opts[:inline] }
107
+ pattern.description = "foo bar"
108
+ expect(subject).to receive(:render_description_with_theme).with("foo bar", hash_including(:language)).and_return("baz qux")
109
+ subject.render_everything
110
+ expect(pattern.description).to eq "baz qux"
156
111
  end
157
112
  end
158
113
  end
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+ require "docks_theme_api"
2
3
 
3
4
  describe Docks::Helpers do
4
5
  describe ".add_helpers_to" do
@@ -17,8 +18,24 @@ describe Docks::Helpers do
17
18
  end
18
19
  end
19
20
 
21
+ it "adds all theme helpers" do
22
+ theme = Docks::Themes::API.instance
23
+ helpers = []
24
+
25
+ Docks.configure_with(theme: theme)
26
+ allow(renderer).to receive(:helpers) do |*args|
27
+ helpers = helpers.concat(args)
28
+ end
29
+
30
+ described_class.add_helpers_to(renderer)
31
+
32
+ Docks.config.theme.helpers.each do |helper|
33
+ expect(helpers).to include helper
34
+ end
35
+ end
36
+
20
37
  it "adds any user-configured helpers" do
21
- Docks.configure_with helpers: ["foo.txt", "bar.txt"]
38
+ Docks.configure_with(helpers: ["foo.txt", "bar.txt"])
22
39
 
23
40
  helpers = []
24
41
  allow(renderer).to receive(:helpers) do |*args|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docks_app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Sauve
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-20 00:00:00.000000000 Z
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet