Class: Texstyles::Style
- Inherits:
-
Object
- Object
- Texstyles::Style
- Defined in:
- lib/texstyles/style.rb
Instance Attribute Summary collapse
-
#symbol ⇒ Object
Returns the value of attribute symbol.
Class Method Summary collapse
-
.respond_to?(method_sym, include_private = false) ⇒ Boolean
We can respond to any method, since we’re indexing into @meta.
Instance Method Summary collapse
-
#initialize(symbol = :authorea) ⇒ Style
constructor
A new instance of Style.
-
#method_missing(method_sym, *arguments, &block) ⇒ Object
Missing methods are assumed to be @meta getters.
- #package_compatible?(package_name) ⇒ Boolean
- #stylize_metadata(options = {}) ⇒ Object
Constructor Details
#initialize(symbol = :authorea) ⇒ Style
Returns a new instance of Style.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/texstyles/style.rb', line 8 def initialize(symbol = :authorea) @symbol = symbol.to_sym style_filename = "#{@symbol}.tex.erb" style_filepath = File.join(Texstyles.root, 'styles', style_filename) @erb = if File.exist? style_filepath ERB.new(File.read(style_filepath)) else nil end = "#{@symbol}.yml" = File.join(Texstyles.root, 'meta', ) = if File.exist? YAML.load_file() else {} end = ['default_packages'] || {} @all_rule = ['*'] @all_compatible = (@all_rule == true) @none_compatible = (@all_rule == false) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
Missing methods are assumed to be @meta getters
75 76 77 |
# File 'lib/texstyles/style.rb', line 75 def method_missing(method_sym, *arguments, &block) [method_sym.to_s] end |
Instance Attribute Details
#symbol ⇒ Object
Returns the value of attribute symbol.
6 7 8 |
# File 'lib/texstyles/style.rb', line 6 def symbol @symbol end |
Class Method Details
.respond_to?(method_sym, include_private = false) ⇒ Boolean
We can respond to any method, since we’re indexing into @meta
80 81 82 |
# File 'lib/texstyles/style.rb', line 80 def self.respond_to?(method_sym, include_private = false) true end |
Instance Method Details
#package_compatible?(package_name) ⇒ Boolean
70 71 72 |
# File 'lib/texstyles/style.rb', line 70 def package_compatible?(package_name) @all_compatible || (!@none_compatible && ([package_name] != false)) end |
#stylize_metadata(options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/texstyles/style.rb', line 31 def ( = {}) @default_packages = ["default_packages"].to_s @header = ["header"].to_s = ["alternative_author_string"].to_s @title = ["title"].to_s @short_title = ["short_title"].to_s = ["authors"] || [] @affiliations = ["affiliations"] || {} # TODO: Refactor these together with the templates into a more elegant workflow, # more aware of multiple affiliations .each do |data| # set the first affiliation as the default one, if not set and we have a list data["affiliation"] ||= (data["affiliations"] && data["affiliations"][0]) end = [0] || {} = ["name"].to_s @first_affiliation = ["affiliation"] && @affiliations[["affiliation"]].to_s = [1..-1].to_a.map{|data| data["name"]} = [1..-1].to_a.map do |data| data["affiliation"] && @affiliations[data["affiliation"]].to_s end @abstract = ["abstract"].to_s if !@abstract.empty? @abstract_begin_end = if @abstract.match(/\{abstract\}/) @abstract else "\\begin{abstract}\n" + @abstract + "%\n\\end{abstract}%\n" end @abstract_command = "\\abstract{" + @abstract + "%\n}\n\n" else @abstract_begin_end = "" @abstract_command = "" end @erb && @erb.result(binding) end |