Skip to content

Commit

Permalink
basic configuration, errors, and parsing structure
Browse files Browse the repository at this point in the history
removed Parser namespace, generated parsing files

Updated namespaces, configuration, and parsing attributes

Updated attributes, and parsing structure

Added model class from configuration for all files and mn, ms, mi, etc classes in math, mstyle, and mrow files

removed namespace for all the tags, updated parsing for Munderover, Msubsup, and others

updated namespace for all tags/classes and linked table, tr, and td with math and other main tags

Added msqrt files

Added msqrt, fenced, and munder classes support

Linked Mroot with root/collection classes

is_mrow for mrow specific check for Plurimath::Math::Formula class

Removed namespace prefix from all files, added msgroup support

Added msgroup, msline, mstack, semantics, and others

Added ms and mrow contents parsing

Added/updated merror, mlongdiv and other tags

Added mpadded and menclose support and updated configuration

Added support for Mfraction, Mphantom, and Mmultiscripts tags

Updated attributes for ms tag

Added mglyph tag support

added lutaml-model version and updated mi and mfenced files

disabled top level documentation

removed namepspace from all files and changed lutaml-model to git branch for testing

test: removed lutaml-model deleted branch

WIP: added specs and relevant changes

Added/fixed spec

fix: rubocop offenses

Added zeitwerk and fixed rubocop offenses

fixed rubocop offenses

removed table_cell_expression file and content

chore: removed unused line from table file

chore: moved development gem from gemspec to gemfile
  • Loading branch information
suleman-uzair committed Nov 12, 2024
1 parent e4e2323 commit 83d45b7
Show file tree
Hide file tree
Showing 54 changed files with 1,895 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ Style/StringLiterals:

Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes

Documentation:
Enabled: false
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ source "https://rubygems.org"
gemspec
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

gem "equivalent-xml"
gem "ox"
gem "pry"
gem "rake", "~> 12.0"
gem "rspec", "~> 3.0"
Expand Down
11 changes: 6 additions & 5 deletions lib/mml.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# frozen_string_literal: true

require_relative "mml/version"
require "zeitwerk"
require "lutaml/model"
require_relative "mml/mml"

module Mml
class Error < StandardError; end
# Your code goes here...
end
loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
loader.ignore("#{__dir__}/lib/mml.rb")
loader.setup
70 changes: 70 additions & 0 deletions lib/mml/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# frozen_string_literal: true

module Mml
module Configuration
SUPPORTED_TAGS = %w[
mmultiscripts
maligngroup
malignmark
munderover
semantics
mscarries
mfraction
mphantom
menclose
mlongdiv
mpadded
msubsup
mscarry
mfenced
msgroup
mglyph
mstack
munder
mtable
mstyle
mspace
msline
merror
msrow
mfrac
mover
mroot
mtext
msqrt
none
mrow
msub
msup
mi
mo
mn
ms
].freeze

module_function

def config
@config ||= {}
end

def config=(config)
self.config.merge!(config)
end

def adapter
Lutaml::Model::Config.xml_adapter
end

def adapter=(adapter)
Lutaml::Model::Config.configure do |config|
require "lutaml/model/xml_adapter/#{adapter.downcase}_adapter"
config.xml_adapter = Lutaml::Model::XmlAdapter.const_get("#{adapter.to_s.capitalize}Adapter")
end
end

def class_for(class_name)
config[class_name]
end
end
end
21 changes: 21 additions & 0 deletions lib/mml/maction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Mml
class Maction < Lutaml::Model::Serializable
model Mml::Configuration.class_for(:maction)

attribute :mathcolor, :string
attribute :mathbackground, :string
attribute :actiontype, :string
attribute :selection, :string

xml do
root "maction"

map_attribute "mathcolor", to: :mathcolor, namespace: nil
map_attribute "mathbackground", to: :mathbackground, namespace: nil
map_attribute "actiontype", to: :actiontype, namespace: nil
map_attribute "selection", to: :selection, namespace: nil
end
end
end
19 changes: 19 additions & 0 deletions lib/mml/maligngroup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Mml
class Maligngroup < Lutaml::Model::Serializable
model Mml::Configuration.class_for(:maligngroup)

attribute :mathcolor, :string
attribute :mathbackground, :string
attribute :groupalign, :string

xml do
root "maligngroup"

map_attribute "mathcolor", to: :mathcolor, namespace: nil
map_attribute "mathbackground", to: :mathbackground, namespace: nil
map_attribute "groupalign", to: :groupalign, namespace: nil
end
end
end
19 changes: 19 additions & 0 deletions lib/mml/malignmark.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Mml
class Malignmark < Lutaml::Model::Serializable
model Mml::Configuration.class_for(:malignmark)

attribute :mathcolor, :string
attribute :mathbackground, :string
attribute :edge, :string

xml do
root "malignmark"

map_attribute "mathcolor", to: :mathcolor, namespace: nil
map_attribute "mathbackground", to: :mathbackground, namespace: nil
map_attribute "edge", to: :edge, namespace: nil
end
end
end
20 changes: 20 additions & 0 deletions lib/mml/math_with_namespace.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Mml
class MathWithNamespace < Lutaml::Model::Serializable
model Mml::Configuration.class_for(:math)

Mml::Configuration::SUPPORTED_TAGS.each do |tag|
attribute :"#{tag}_value", Mml.const_get(tag.capitalize), collection: true
end

xml do
root "math", mixed: true
namespace "http://www.w3.org/1998/Math/MathML", nil

Mml::Configuration::SUPPORTED_TAGS.each do |tag|
map_element tag.to_sym, to: :"#{tag}_value"
end
end
end
end
19 changes: 19 additions & 0 deletions lib/mml/math_with_nil_namespace.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Mml
class MathWithNilNamespace < Lutaml::Model::Serializable
model Mml::Configuration.class_for(:math)

Mml::Configuration::SUPPORTED_TAGS.each do |tag|
attribute :"#{tag}_value", Mml.const_get(tag.capitalize), collection: true
end

xml do
root "math", mixed: true

Mml::Configuration::SUPPORTED_TAGS.each do |tag|
map_element tag.to_sym, to: :"#{tag}_value"
end
end
end
end
25 changes: 25 additions & 0 deletions lib/mml/menclose.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Mml
class Menclose < Lutaml::Model::Serializable
model Mml::Configuration.class_for(:menclose)

attribute :mathcolor, :string
attribute :mathbackground, :string
attribute :notation, :string
Mml::Configuration::SUPPORTED_TAGS.each do |tag|
attribute :"#{tag}_value", Mml.const_get(tag.capitalize), collection: true
end

xml do
root "menclose", mixed: true

map_attribute "mathcolor", to: :mathcolor, namespace: nil
map_attribute "mathbackground", to: :mathbackground, namespace: nil
map_attribute "notation", to: :notation, namespace: nil
Mml::Configuration::SUPPORTED_TAGS.each do |tag|
map_element tag.to_sym, to: :"#{tag}_value"
end
end
end
end
23 changes: 23 additions & 0 deletions lib/mml/merror.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Mml
class Merror < Lutaml::Model::Serializable
model Mml::Configuration.class_for(:merror)

attribute :mathbackground, :string
attribute :mathcolor, :string
Mml::Configuration::SUPPORTED_TAGS.each do |tag|
attribute :"#{tag}_value", Mml.const_get(tag.capitalize), collection: true
end

xml do
root "merror", mixed: true

map_attribute "mathcolor", to: :mathcolor, namespace: nil
map_attribute "mathbackground", to: :mathbackground, namespace: nil
Mml::Configuration::SUPPORTED_TAGS.each do |tag|
map_element tag.to_sym, to: :"#{tag}_value"
end
end
end
end
33 changes: 33 additions & 0 deletions lib/mml/mfenced.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module Mml
class Mfenced < Lutaml::Model::Serializable
model Mml::Configuration.class_for(:mfenced)

attribute :mathbackground, :string
attribute :separators, :string
attribute :mathcolor, :string
attribute :content, :string
attribute :close, :string
attribute :open, :string
Mml::Configuration::SUPPORTED_TAGS.each do |tag|
attribute :"#{tag}_value", Mml.const_get(tag.capitalize), collection: true
end

xml do
root "mfenced", mixed: true

map_content to: :content

map_attribute "mathbackground", to: :mathbackground, namespace: nil
map_attribute "separators", to: :separators, namespace: nil
map_attribute "mathcolor", to: :mathcolor, namespace: nil
map_attribute "close", to: :close, namespace: nil
map_attribute "open", to: :open, namespace: nil

Mml::Configuration::SUPPORTED_TAGS.each do |tag|
map_element tag.to_sym, to: :"#{tag}_value"
end
end
end
end
31 changes: 31 additions & 0 deletions lib/mml/mfrac.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

module Mml
class Mfrac < Lutaml::Model::Serializable
model Mml::Configuration.class_for(:mfrac)

attribute :mathcolor, :string
attribute :mathbackground, :string
attribute :linethickness, :string
attribute :numalign, :string
attribute :denomalign, :string
attribute :bevelled, :string
Mml::Configuration::SUPPORTED_TAGS.each do |tag|
attribute :"#{tag}_value", Mml.const_get(tag.capitalize), collection: true
end

xml do
root "mfrac", mixed: true

map_attribute "mathcolor", to: :mathcolor, namespace: nil
map_attribute "mathbackground", to: :mathbackground, namespace: nil
map_attribute "linethickness", to: :linethickness, namespace: nil
map_attribute "numalign", to: :numalign, namespace: nil
map_attribute "denomalign", to: :denomalign, namespace: nil
map_attribute "bevelled", to: :bevelled, namespace: nil
Mml::Configuration::SUPPORTED_TAGS.each do |tag|
map_element tag.to_sym, to: :"#{tag}_value"
end
end
end
end
31 changes: 31 additions & 0 deletions lib/mml/mfraction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

module Mml
class Mfraction < Lutaml::Model::Serializable
model Mml::Configuration.class_for(:mfraction)

attribute :mathcolor, :string
attribute :mathbackground, :string
attribute :linethickness, :string
attribute :numalign, :string
attribute :denomalign, :string
attribute :bevelled, :string
Mml::Configuration::SUPPORTED_TAGS.each do |tag|
attribute :"#{tag}_value", Mml.const_get(tag.capitalize), collection: true
end

xml do
root "mfraction", mixed: true

map_attribute "mathcolor", to: :mathcolor, namespace: nil
map_attribute "mathbackground", to: :mathbackground, namespace: nil
map_attribute "linethickness", to: :linethickness, namespace: nil
map_attribute "numalign", to: :numalign, namespace: nil
map_attribute "denomalign", to: :denomalign, namespace: nil
map_attribute "bevelled", to: :bevelled, namespace: nil
Mml::Configuration::SUPPORTED_TAGS.each do |tag|
map_element tag.to_sym, to: :"#{tag}_value"
end
end
end
end
45 changes: 45 additions & 0 deletions lib/mml/mglyph.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

module Mml
class Mglyph < Lutaml::Model::Serializable
model Mml::Configuration.class_for(:mglyph)

attribute :alt, :string
attribute :src, :string
attribute :width, :string
attribute :color, :string
attribute :index, :integer
attribute :height, :string
attribute :valign, :string
attribute :mathsize, :string
attribute :fontsize, :string
attribute :fontstyle, :string
attribute :mathcolor, :string
attribute :fontfamily, :string
attribute :fontweight, :string
attribute :background, :string
attribute :mathvariant, :string
attribute :mathbackground, :string

xml do
root "mglyph"

map_attribute "src", to: :src, namespace: nil
map_attribute "alt", to: :alt, namespace: nil
map_attribute "color", to: :color, namespace: nil
map_attribute "index", to: :index, namespace: nil
map_attribute "width", to: :width, namespace: nil
map_attribute "height", to: :height, namespace: nil
map_attribute "valign", to: :valign, namespace: nil
map_attribute "mathsize", to: :mathsize, namespace: nil
map_attribute "fontsize", to: :fontsize, namespace: nil
map_attribute "fontstyle", to: :fontstyle, namespace: nil
map_attribute "mathcolor", to: :mathcolor, namespace: nil
map_attribute "background", to: :background, namespace: nil
map_attribute "fontfamily", to: :fontfamily, namespace: nil
map_attribute "fontweight", to: :fontweight, namespace: nil
map_attribute "mathvariant", to: :mathvariant, namespace: nil
map_attribute "mathbackground", to: :mathbackground, namespace: nil
end
end
end
Loading

0 comments on commit 83d45b7

Please sign in to comment.